This time it’s not a fractal.
Let say, you’ve got a pendulum full of sand. You set a movement, kind of a rotation.
At first the sand will draw an ellipse. With the rotation speed decreasing, the ellipse become an circle.
After a while, it’s an ellipse again, and then a circle again, but not in the same direction.
That combination of speed, rotation and angle is the key.
Lissajous curve table is the demonstration.
Let start as the previous one with an html file,
and a canvas.
Let’s grab the canvas and it’s dimension, we’ll use the 2D context here.
And we add some configuration.
We are going to draw/update everything every 33ms, which is about 30 images / second.
Let’s start with the columns.
Now the rows.
Now I’ll draw the referential ellipses all around the table.
So I need a function to draw an ellipse.
I can draw them in the drawCols and drawRows methods.
Now I want to draw a point that will evolve at different speed in each circle.
So I’ll need to update the angle at each iteration, and draw the point
Inside we’ll draw the curves. For this I’ll use a class.
We are going to need to keep track to of each point for each curve, and set the position between each iteration.
Two setters for the position.
A method to add a new point in the history.
And to finish we need a method to draw these points.
Let initialize each curve according to the number of columns and rows.
Now we need to update the position of the curve between each iteration.
The x position has to be updated when drawing the columns and the y position has to be updated when drawing the rows.
We are almost done. We still need to add these points to the curve in each iteration.
Mesmerizing!
If We want this to be alright, we need to reset the paths after each revolution.
Otherwise we’ll end up with too much points to handle.
Now it’s your turn. Try it.
What would be the result if I set the canvas size to 1200x1200 or even larger?
Maybe play with colors, superposition, timing… Send me yours :)