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:
  • circle of size x
  • color (from standard tclTK-colors)
  • outline or filled
  • time to live (disappear after n seconds)
  • direction vector and speed
  • focal point (origin in X,Y)
The graphics.py library doesn't have collision detection, so I had to code for that. I wrote 3 separate screen savers, with the same underlying code. Just the control logic changed. Clicking on the items below will start a short clip.

  1. 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


  2. 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


  3. 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.

   « Back to Previous Page

   « Back Home

Featured Links


Random Favorite Quotes

"It's all good!"

"There is a theory which states that if anyone discovers what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.
There is another theory which states that this has already happened."
– Douglas Adams, The Hitchhiker's Guide to the Galaxy