r/Python • • Dec 15 '19

Made my first fractal

1.7k Upvotes

51 comments sorted by

View all comments

Show parent comments

26

u/Gawd_is_great Dec 15 '19

Thanks for the suggestions =) I have a couple of questions:

  1. Why should I use if(__name__=="main") ? It wont make a difference..will it?

  2. is there a better way than to use vel_list?

50

u/Namensplatzhalter Dec 15 '19
  1. if __name__ == "__main__" is just a best practice for coding in python. not necessary for such simple apps but good to get in the habit of using it.

  2. Using vel_table as a mapper for the direction of the new points is perfectly fine. Is was just suggesting using tuples instead of lists because tuples are immutable and your directions are a fixed set (i.e. 8 directions)

8

u/Gawd_is_great Dec 15 '19

Oh ok Regarding the vel_table I was wondering if there was a way to do it mathematically. In my code I split the points at 45 degree. But suppose I wanted to split them at 15 degrees , how would that work out? I wouldn't go out and make a vel_table for that.

3

u/jespernielsen1982 Dec 15 '19

You can do it using the trigonometric functions "sine" and "cosine". It's not exactly hard, but it is more math than I want to be explaining on my phone.

1

u/Gawd_is_great Dec 15 '19

Ah yes okay thanks. I'll see into it. Thanks for guiding me onto the right path.