/* PushTranslateRotateScalePop, D. Parson, September 2022 demo of these transforms. */ void setup() { // Runs once when sketch is started. size(1000, 850); // Do size() or fullScrenn() first. frameRate(60); // Set frameRate explicitly for new macs, 60 is the normal default. rectMode(CENTER); // x, y location for plotting is at the center of the rectangle & ellipse ellipseMode(CENTER); background(0, 255, 255); // cyan, see c0lor tool } float rotateWorld = 0.0 ; // degrees float rotateWorldIncrement = 0.0 ; // 1.0 ; void draw() { // Invoked once per 1.0/frameRate, e.g., every 60th of a second // BUG rotate(radians(rotateWorld)); // [0.0, TWO_PI] radians same as [0.0, 360.0] degrees // BUG rotateWorld += rotateWorldIncrement ; // automatically treats 360 as 0, etc. background(0, 255, 255); // erase over drawing from the previous frame (call to draw()) push(); // Combines pushMatrix() and pushStyle(), look them up in Reference. translate(width/2, height/2); // place 0,0 location at center of display. rotate(radians(rotateWorld)); // [0.0, TWO_PI] radians same as [0.0, 360.0] degrees rotateWorld += rotateWorldIncrement ; // automatically treats 360 as 0, etc. for (float scaleFactor = 1.0; scaleFactor > 0.0; scaleFactor -= 0.1) { // 0.5 or 0.1 display(scaleFactor); } pop(); // popMatrix()+popStyle(), pairs with most recent push(). } void display(float scaleFactor) { println("DEBUG display scaleFactor " + scaleFactor); push(); // save incoming coordinate space before changing. strokeWeight(3); // need to be bolder to show up, try strokeWeight(3/scaleFactor); // I am going to plot myself at 4 locations, so doing a nested push inside this loop. for (float angle = 0.0; angle < 360.0; angle += 90.0) { push(); // prepare top rotate the world rotate(radians(angle)); // convert to radians int translation = min(width/4, height/4); // halfway fro, center of display translate(translation, 0); // translate in X direction after it has been rotated scale(scaleFactor); // do not scale the preceding translation, just scale the shape fill(255, 0, 255); // R and B yield magenta stroke(0, 255, 0); // Green ellipse(0, 0, 200, 200); // plot at innermost translation center, size scaled by scaleFactor noFill(); // ellipse(X,Y,Width, Height) stroke(0); for (int xoffset = -100; xoffset <= 100; xoffset += 100) { for (int yoffset = -100; yoffset <= 100; yoffset += 100) { // instead of push()ing and translate()ing we''l just use rect(X,Y,W,H) location parameters rect(xoffset, yoffset, 50, 50); } } pop(); // pops the push inside the outter for loop that wraps inner rotate,translate,scale } // end of outer for loop pop(); // pops the incoming push() to return to the caller's coordinate system }