//************************************************ //*** 2D animation written by Jarek Rossignac to illustrate how to rotate //*** an object around an arbitrary center (here, the cursor location) //************************************************ float t=0; // animation time void setup() { // ** SETUP (executed once at initalization) ** size(500, 500, P3D); // opens window of given size PFont font = loadFont("Chalkboard-Bold-48.vlw"); textFont(font, 24); // loads font (use >Tools>Create Font> to change font } void draw() { // ** DRAW (executed at each frame) ** background(255); // erases screen with white background fill(0); text("Press mouse to specify center of rotation",15,20); // frame origin is at upper left corner translate(mouseX, mouseY); // translate frame to mouse (center of rotation) if(mousePressed) rotateZ(cos(t*PI)); // rotation around mouse translate(-mouseX, -mouseY); // translate frame back back translate(width/2,height/2); // move frame to center of screen fill(250,50,50); // color (RGBa<255) for text text("Jarek Rossignac",-100,-20); // display text offset to be centered at origin of frame t+=0.03; // advance animation }; // end draw