home/ atoms/ processing-rotate-scale

rotate() and scale() in Processing transform geometry in local coordinate space, not screen space

rotate(angle) rotates all subsequent drawing around the current origin by angle in radians. scale(factor) multiplies all subsequent coordinates by factor. The order of transformation calls matters: translate then rotate differs from rotate then translate because each operation is applied in the current (transformed) coordinate space. Combining pushMatrix/popMatrix with nested translate+rotate is the standard pattern for articulated figures or orbital motion. scale() also scales strokeWeight, which can produce unexpected results in complex scenes.

Examples

translate(50, 50); for (int i = 0; i < 12; i++) { rotate(TWO_PI/12); line(0, 0, 40, 0); }

Assessment

Predict the visual output of: pushMatrix(); translate(50,50); rotate(PI/6); rect(0,0,30,10); popMatrix(). Draw a diagram showing where the rectangle appears.

“These simple examples demonstrate the potential in combining transformations but also make clear that transformations require thought and planning.”
corpus · processing-handbook-no-login-mirror-pdf-reas-and-fry · chunk 36