Main menu

Fractals, Cellular Automata, Chaos Theory, Science, Space, etc

Tag Archives: spirograph

Daniel Shiffman has been making YouTube movies for some time now. His videos focus on programming and include coding challenges in which he writes code for a target idea from scratch. If you are a coder I recommend Dan’s videos for entertainment and inspiration.

Fractal Spirographs (aka Fractal Routlette) are generated by tracking a series (or chain) of circles rotating around each other as shown in the above gif animation. You track the chain of 10 or so circles and plot the path the final smallest circle takes. Changing the number of circles, the size ratio between circles, the speed of angle change, and the constant “k” changes the resulting plots and images.

How I Coded It

As I watched Daniel’s video I coded my own version. For my code (Delphi/pascal) I used a dynamic array of records to hold the details of each circle/orbit. This seemed the simplest approach to me for keeping track of a list of the linked circles.

I have already experimented with 3D Spirographs in the past, but they are using spheres rotating within other spheres. Plotting the sqheres rotating around the outside of other spheres should give more new unique results.

Ahhh, Spirograph, that simple set of plastic cogged discs and rings that created a huge amount of spirally patterned goodness (as long as you kept a steady hand and didn’t jump a cog tooth). I still remember how cool they were prior to the home computer age. Here is a 1973 commercial for them.

And here is a commercial from the 80s.

Visions Of Chaos currently supports rendering 2D spirographs, but I have wanted to explore a 3D extension of Spirographs for a long time.

It was surprisingly difficult to find the formulas required to plot the 3D result of spheres rotating within spheres within speheres etc. Finally, thanks to Henry de Valence’s code I was able to add 3D Spirographs to Visions Of Chaos.

OpenProcessing is a goldmine of ideas/formulas/algorithms. Anyone who enjoys computer graphics and programming needs to check it out.

Here are two early sample movies resulting from my initial test code.

Once they showed potential I made sure that Visions Of Chaos supported the true 1080p “real side by side 3d” output and got the following result. This looks amazing on my LG 3D TV with the polarised glasses. They really pop what seems at least a foot out of the screen as they rotate.

If you want to have a play with the new 3D Spirograph mode, download Visions Of Chaos.

Info For Coders

If you are a programmer who is looking to explore the incredible space of 3D Spirographs here is the main code that you will need to plot the curve in 3D space. This is a direct copy and paste from Henry’s processing code.

num_segments is how many recursive spheres within spheres you use. For the above sample 3D movie most of them used 2 spheres, but any higher number works too and will lead to much more complex and twisted plots.

r[i] are the radius lengths of each sphere or arm segment.

f[i] and g[i] are non zero +/- period values that change the resulting plot shapes. I tested and used values between -45 and +45 for my images and movies to extend the possible resulting shapes. If the values are rational (integer numbers) then the plot will eventually come back to the start point and retrace itself.

t is time that starts at 0 and should be changed 0.01 or so per update for a smooth plot.

the ax to bx etc swapping keeps track on the sphere within sphere.

Once the segment loop is finished bx,by and bz are the next 3D point in space the Spirograph is at.

At this stage you should be plotting nice 3D spirographs. One very helpful tip is how to work out when to stop calculating and plotting new points. As stated above if you use integer values for the periods then the plot will always return to the start position and beging retracing itself again. Being able to pre-calculate how many steps the plot needs is a handy feature to have.

To calculate the ideal value that the time t variable will be when the plot finishes you find the least common multiplier (LCM) of all the period values. eg if you have a spirograph using 3 arms/segments you will need to calculcate the LCM of 6 period values. Chances are your programming language of choice has a LCM(a,b) function that takes two values. For 3 or more values you recursively call the LCM function. ie the LCM of a,b and c is LCM(a,LCM(b,c)). Thanks again to Henry for the LCM tip.