Fun with "particles"
Having fun playing with Python object oriented programming and writing screen savers: particles.py is simple code that uses the graphics.py library written by John Zelle. Objects of class "particles" are assigned these attributes randomly at instantiation:
|
- particles cannon clip: As particle objects (circles) of random sizes/colors are instantiated, they appear on the left of the screen, moving at random speeds towards the right. Each has a direction vector from X0,Y0 to Xn,Yn – which changes as the particles bounce off the edges of the screen. Their point-of-origin moves up/down on the left. Cannon source code here
- particles collision clip: Particles are created and bounce around the screen using the same class, methods, and functions. This time the control logic creates a special red "destroyer" particle that eats the others as they collide. The screen saver resets after 45 seconds or when all the particles disappear. Any particle that survives without being eaten is a "winner" and wins a chicken dinner. Collision source code here
- bubbles clip: Creates particles at the bottom of the screen. They rise to the top like air bubbles in water. Their vector and speed of rise is random. Again using the same class, methods, and functions but this time the animation is different and the particles are only outlined. For a cool effect, the bubbles stay at the bottom for a little while before they rise. Bubbles source code here
I'm loving coding in Python. Most of my past coding was in "C" and Perl. Python is a very elegant language and fun to code. I wrote these short programs to experiment with the language and amuse myself... this is how I spend Friday nights. ☺