Two-disk Hypotrochoid Generator in Python

After picking up a little spirograph kit at the dollar store and playing around with it for a while, I wondered what it would be like if a second disk could rotate around the first disk. This not being physically possible, I decided it’d be a good time to practice my Python as well. After a couple evenings of fiddling, I was able to come up with some nice-looking images using just the math library and Python Imaging Libary.

Here’s the first image that was successfully generated. I stopped drawing prematurely so there are gaps, and the simulated disk was actually rotating the opposite way than a physical spirograph disk would.

hypotrochoid 1

Here I successfully simulated a standard physical spirograph and used some nicer colors.

hypotrochoid 2

Here’s a result I got after trying out some different coloring methods. I think this one alters the color based on the radians used to rotate one of the disks.

hypotrochoid 3

Here’s my first attempt at simulating a second disk rotating around the first disk. Pretty chaotic.

hypotrochoid 4

This last one is my favorite image that I’ve been able to come up with, simulating a 2nd disk rotating around the first disk. The rate of rotation and other parameters really make the difference between fantastic and terrible.

Hypotrochoid 5

It’s sloppy and not very fast, but it works. Simulating circular disks was a fairly simple affair, but simulating a triangular, square, or football shaped disk would be significantly harder.

Code found here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s