I ask myself if sharing the code to programs like this one would be useful to anyone. It’s written so fast, with so many one letter variables, and so few comments that it’s probably not so helpful. But here it is anyway.
I think the concept is more interesting than the code. One idea made me write this program. I thought that in many sketches it’s clear what is in front and what is behind. This happens because things just get added to the screen, on top of everything else. But what if I wanted to have objects that could be in front and behind other objects?
So I thought of making tubes that revolve around each other. The tubes are actually made of spheres, but they look flat because I did not call lights(). I wanted to have this flat look.
Drawing actual tubes would be much more efficient than drawing spheres. But since no one is paying me to write efficient code… :)
The whole shape must be drawn in one frame for depth sorting to work. If you would add new shapes on new frames, the new shapes would always cover previously drawn graphics, even if they were supposed to be behind other objects. Depth sorting takes care of making objects which are closer to you cover objects which are further away from you.
The alternating colors make the motion more interesting. Without them, it looks like the shape is just spinning around its center. With the alternating colors some confusion is added: the stripes try to be still, but the waves keep waving and rotating.
The glow is just a simple filter(BLUR, 6) call. I made one of the tubes black to avoid the blur to spreading all over the screen. This way I keep the glow under control.
For creating the animated gif I used this command:
gifsicle --delay=4 --loop --dither
--rotate-270 --colors 24 *.gif > /tmp/anim.gif