Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
When translate() and rotate() are combined, the order in which they appear affects the result. The following example is identical to Example 7-19: Rotation, except that translate() and rotate() are reversed. The shape now rotates around the upper-left corner of the display window, with the distance from the corner set by translate():
floatangle=0.0;voidsetup(){size(120,120);smooth();}voiddraw(){rotate(angle);translate(mouseX,mouseY);rect(-15,-15,30,30);angle+=0.1;}
You can also use the rectMode(), ellipseMode(), imageMode(), and shapeMode() functions to make it easier to draw shapes from their center.