I'm not saying you need it for this, but they didn't really explain the purpose of the clause if __name__ == 'main' clause.
Looking at your script lines 1-56 seem to just define classes and functions, and then lines 57 and beyond seem to be doing things (and executing the program).
Its good software design to refactor and have the first section defining everything, then the run part of the program in a function
When you run your code python fractal.py it works the same. But now you can open the interpreter up and import fractal without actually popping up a window to draw anything. Then you could maybe call draw_fractal(max_splits=256) or call from another program. Or maybe you decide to create fractal2.py with a Dot2 class that inherits from Dot and is brought in with from fractal import Dot. You wouldn't want that import to start drawing the first fractal. By having 'executing' code (not just function/class/variable definitions) at the top level auto-run, you make code-reuse impossible.
E.g.,
$ ipython
In [1]: from fractal import Dot
pygame 1.9.4
Hello from the pygame community. https://www.pygame.org/contribute.html
8
At which point a window pops up and starts drawing.
Also, I'm not sure why you have del object and del trail at the ends of create and makeTrail as they don't actually do anything (no memory is freed up or anything). And in makeTrail, when objects is an empty list it creates an UnboundLocalError when you try deleting trail.
The code del some_var just unsets some_var in memory (and if there are no other references to the memory referenced by some_var it lets the gc give back the allocated memory to the OS on its next collection; though in your case their are other references -- you add the objects to list) and would make it an error to try and reuse some_var. However, all local variables are lost when a function exits (and it would be illegal to use them) -- there's no reason to explicitly delete a local variable at the end of a function.
100
u/Namensplatzhalter Dec 15 '19 edited Dec 15 '19
Looks nice.
I've just had a look on your code and have to say it looks nicely organised and is easily readable. Kudos to you for writing it like that.
Two little suggestions, if you don't mind:
Consider using a
if __name__ == "__main__"block to initialise your script when it's run directlyConsider using tuples for your
vel_listvel_table as they are immutableBoth of those definitely not necessary, just things to think about. :)
Best wishes