I wanted to learn Python and decided to go about it by making something with Pygame. Something became a clock and, if not very practical, it is kind of fun to look at.
The particles set off in a random direction downwards until they bump into something and they will continue to fall as long as there is nothing below them. The idea was to model water, sand or anything that would be able to find its own level. Over the course of the hour particles will randomly disappear at a set rate to keep time. Diffusion Limited Aggregation with Evaporation Clock is too long a title, so Particle Clock will have to do.
It took 13 hours over approximately 2 weeks to get the logic all worked out. The frame rate is abysmal on my ancient machine. Reasonably modern computers that don't have badly misconfigured graphics, like my even more ancient laptop, can easily get 10 fps. I've tried all the obvious speed boosts: no alpha compositing, not updating things that don't need to be, and other stuff that a Google search for "pygame slow" turned up. This just shows that I haven't developed the habit of benchmarking before optimizing, even though I know better. None of it made any difference; the sheer number of particles and the collisions amongst them is totally overwhelming. The benchmark pointed directly at spritecollide and groupcollide.
Pushing the framerate higher will require only checking for collisions in the area each particle is in, which will complicate things more than I care to deal with for now. As long as the animation can run at more than 5 fps it will keep time correctly.
Particle Clock script: clockDecember 6, 2008
Yay! I somehow managed to get py2exe to work. I think mainly by giving the setup file nasty looks and trying random stupid things. However, I also, through total lack of revision control, reverted to a version that I had fixed. And I don't remember what the fix was. But py2exe! Yay!
Particle Clock Windows exe: clock.zip
There is an exe in there somewhere. It has been tested on a whole one machine apart from the one it was packaged on, so it will clearly run without a flaw no matter what!June 25, 2009