This project centers around the creation of short animations using Python script. One of the primary goals for these animations is to be used as clips for music visualizers, but the animations can also be used to create standalone GIFs or videos.
Note: This repo is under construction. I need to organize it better and add the code for each example, but I've gone ahead and made this public to show the results. I'd also like to update the code to be more functionalized, so that it can be used in a more input/output style.
The bubble animations make use of the PIL library which allows for drawing of different basic shapes such as circles (actually ellipses). In order to get the bubbly effect, small circles are drawn which then grow in size over the remaining duration of the GIF. Each bubble is tracked as its own instance with its own unique set of instantaneous properties (center point, radius, and color). Note that the PIL draw function accepts top-left and bottom-right coordinates of the ellipse's bounding box, so a conversion is done between center point/radius and these coordinates. The GIF is structured as a sequence of images containing nframes frames. The code loops through each frame, one at a time, and updates the properties of each circle in that frame. The result is a two-level nested for loop.
Growth is imparted to the bubbles by subtracting an amount grow from the top-left coordinate and adding that same amount to the bottom-right coordinate. Typically grow is kept constant, although in the cases with motion, I found that adding a little bit of variability to the growth rate gave a slightly more organic feel. To capture this functionality, possible values for grow are put into a list called grows (e.g. [5,6,7]), and then grow is defined as a random selection from grows by applying the choice function. A continuous function could have been applied here instead of a random choice. Motion is handled similarly with the variables m and ms. Motion is imparted to the bubbles by adding an equal amount of m to the top-left and bottom-right coordinates of the circles. In the case where the bubbles are drifting (third from left), a continuous function dependent on the current frame value f is defined to control the change in trajectory of the bubbles. Finally, bubble color is set for each bubble at each frame, so the bubble colors can be unique and change from frame to frame as they do in the instances with the rainbow, strobing effect.
It might be cool to add a "popping" effect to this animation. After all, bubbles don't just grow indefinitely. This would likely entail a simple conditional statement addressed before each bubble is updated in each frame which asks if the bubble has reached a certain radius yet.
Look closely... They're twinklin'.
In the stars animation, a random distribution of small circles is created and used to initially populate the canvas. The twinkling effect is created by adding a subtle jittering motion and brightness change to each of the stars. The jitter is triggered by adding a value randomly selected (using the choice function) from the list m_seq which contains a small negative value, some number of zeros, and a small positive value equal in magnitude to the negative value (e.g. m_seq = [-0.001, 0, 0, 0, 0, 0, 0.001]). Since the list has mostly zeros, the stars will mostly not move, but occasionally one of the non-zero values will be selected and the star will jitter. Similarly, the brightness level is randomly selected from a list called c_seq which contains values between 0 and 1 (e.g. c_seq = [0.6,0.65,0.7]). The instaneous color of each star is then defined as an RGB triplet (c, c, 0.8c) where c=choice(c_seq). The blue value in the RGB triplet is made to be slightly less, so that the stars will all have a slightly yellow tint.
This script uses the pycairo library, which I wanted to try instead of PIL and Skimage because it is built on fractional units (e.g. circle radius is set to a fraction of the overall canvas width), which can make resizing things very convenient. However, I still make use of PIL, because the final conversion to GIF uses PIL. Thus, I needed a way to convert cairo surfaces to PIL images. I made use of a function found here: http://www.casualhacker.net/post/2013-06-02-convert-pycairo-argb32-surface-to-pil-rgb-image/. Also note that Pycairo was somewhat difficult to install. I might add some instructions for that. it was something I did a long time ago.
Probably more on the snow end of the spectrum.











