Project #5: Optical Illusion

Description

Click to see how the circles are moving.

This is one of my favourite optical illusions, so I decided to recreate it in code. The circles look like they're rotating around, but they're actually just moving back and forth along a line at different intervals. The combined effect is that it looks like a larger circle rotating around.

Design Process

I tried a few different illusions for this assignment. I decided to do this one because I've been fascinated with how it works for a long time.

The lines and the circles actually came together fairly quickly. I used a sine curve to create the oscillating motion of each of the moving circles.

I ran into some trouble figuring out how to make the circles move at different positions, so they could resemble a circle as they moved along their lines. I tried a few different time-dependent strategies, but those did not give me the result I was looking for. Finally, I was able to use a phase shift to each of the sine curves to alter the position of each circle.

Reflection

Although for loops were confusing to me when they were first introduced, I feel like over the course of figuring out how to build this and the details involved in it, I have a fairly good grasp on them now. The part where I had to increment the phase shift for the sine curves inside the for loop where I called the drawCircles function was tricky, but I finally figured it out (with some help).