Learn creative coding writing simple programs

30. Multiple rotating objects and reset matrix

Previously we animated a rotating rectangle. This time we animate not only one, but four rectangles.
To rotate an object around its own center we must move the origin and rotate the axes. This works fine when there is only one object, but to rotate more than one object is tricky, because each time translate() and rotate() are called, the effect adds to previous calls to translate() and rotate(). To solve this we introduce resetMatrix(), which removes previous changes to the origin and axes rotation.
Basically we do 1. translate(), 2. rotate(), 3. draw something, 4. resetMatrix() to undo the effects produced by 1 and 2. Then repeat 1, 2, 3 and 4 for other rotating objects.

Tags: resetmatrix

Code editor

You can make changes to the code below. Then

Questions and comments

Try to stay close to the topic of this episode. Use the Processing forums for help with unrelated Processing projects (or hire me for help ;-)

To indicate that a word in your comment is code, use the `backtick`. Example
  Do `float` and `int` smell similar?
To highlight code blocks, use ```processing and ``` like this:
  void setup() {
    size(600, 600);