Animation Using Transforms
Animate Rotating Ellipses - Use Transforms
In the image below, we can look at 2 different approaches for animating ellipses.
Animation requires use of the draw loop, and a global variable:
xPos
, that's incremented within the draw loop:xPos++
Rotation of objects requires that the canvas origin must be moved to the center of the object, then rotate( angle) causes the canvas to rotate - around the origin, which is now also the location of the object's center. If
angle
is a global variable that's incremented, then rotation will be animated:angle++
The blue ellipse has xPos
animated:
The yellow ellipse is animated, through translation of the origin, and rotation around the origin, the ellipse is drawn at the origin: ellipse( 0,0,100, 30);
Relative Positioning Animation - PushMatrix / PopMatrix
Below is an example of how transforms can be used to create a simple character, we can use pushMatrix() and popMatrix() to save and retrieve canvas configuration settings as noted in the image below. pushMatrix and popMatrix are designed to be used together, you call pushMatrix when you know that you will want to return to the current configuration. This is common when trying to create symmetry relative to a fixed reference point like the character's nose.
Last updated