/* 6.914, Example 3.0 There are three major coordinate transformations in Processing: rotate, translate, and scale. We have one operation to apply stacked transformations (pushMatrix) and another to remove them (popMatrix). 0) rotate(rads) rotates your coordinate axis around the origin in the upper left corner. It takes radians as an argument, so if you want to pass something in degrees, use the radians() function to convert it. Rotations using rotate have standard mathematical relations to one another, meaning that this: rotate(.75 * PI); rotate(.5 * PI); will have the same effect as this: rotate(1.25 * PI); Rotating 2*PI will have no effect. 1) translate(x, y) moves your coordinate axes x degrees left and y degrees downwards. (You can pass negative values to move in the opposite direction.) Again, standard mathematical operations apply, so these two transformations are equivalent: translate(50, -40); translate(20, 30); and translate(70, -10); 2) scale(scaleDegree) scales up each pixel by the size decided. So, a scaleDegree of 2 will make the area of any rectangles increase by 4x. A scaleDegree of 1.0 will not have any effect. 3) pushMatrix and popMatrix allow you to apply a series of transformations, and then remove them, using whatever groupings are most convenient. You add transformations to the top of a stack by first calling pushMatrix(), then calling the transformations. Calling popMatrix() after drawing in that coordinate system will restore you to the previous coordinate system. */ void setup(){ size(400, 400); } void draw(){ background(0); translate(width/2, height/2); // move coordinate axist to center of screen for (int i = 0; i < 5; i ++){ pushMatrix(); // changing from original coordinate system scale(random(1,1.2)); rotate(random(.25*PI)); // rotate less than 45 degrees // you can use println() and degrees() to check this rect(-width/4, -height/4, width/2, height/2); popMatrix(); // return to original coordinate system // so that new coordinate transformations do not vary much from original } delay(150); }