import processing.opengl.*; // using openGL improves texture quality and performance // Project P01: 3-D animation of text and textured polygon // Written by Jarek Rossignac July 2008 // Student should edit this code to create two new animations using his/her name and picture PImage myImage; // variable referencing image for texture String name="Jarek Rossignac"; // string containing name to be rendered float w = 300; // desired size of image in the final picture float tm=100, t=tm; // max time and current time use for animation boolean first=true; float x=0,y=0; // mouse controlled variables void setup() { // ** SETUP (executed once at initalization) ** size(600, 600, OPENGL); // opens window of given size PFont font = loadFont("Chalkboard-Bold-48.vlw"); textFont(font, 48); // loads font (use >Tools>Create Font> to change font myImage = loadImage("jarek.jpg"); // load image for texture (file in the Data folder) textureMode(NORMALIZED); // texture parameters in [0,1]x[0,1] noStroke(); // will not draw border of rectangle fill(0,50,50,200); // transparent color (RGBa<255) for text } void draw() { // ** DRAW (executed at each frame) ** background(255); // erases screen with white background if (t>0) t--; else t=0; if (first) if (t>0) moveImage1(); else first=false; else moveImage2(); if (first) if (t>0) moveText1(); else first=false; else moveText2(); if (mousePressed) {x=mouseX; y=mouseY; t=tm;}; // change parameters for second animation }; // end draw void moveImage1() { pushMatrix(); translate(width/2, height/2); // 2D translation rotateZ(t*PI/tm); scale(w); // uniform scale renderImage(); popMatrix(); } void moveText1() { pushMatrix(); translate(width/2, height/2); // 2D translation rotateX(TWO_PI*t/tm); renderText(); popMatrix(); } void moveImage2() { pushMatrix(); translate(t*(x-width/2)/tm,t*(y-height/2)/tm,0); rotateY(t*PI/tm/4); translate(width/2, height/2); // 2D translation scale(w); // uniform scale renderImage(); popMatrix(); } void moveText2() { pushMatrix(); rotateY(2.0*TWO_PI*x*t/tm/width); translate(width/2, height/2); // 2D translation rotateX(TWO_PI*t/tm); renderText(); popMatrix(); } void renderImage() { beginShape(); // start drawing/filling polygon texture(myImage); // specifies which texture will be used vertex(0, 0, 0, 0); vertex(1, 0, 1, 0); vertex(1, 1, 1, 1); vertex(0, 1, 0, 1); // vertices (x,y,s,t) endShape(); } void renderText() {text(name,5,20); } //** KEY ACTIONS (executed each time a key is pressed void keyPressed() { if (key==' ') {t=tm; first=true;} // reset time when space bar is pressed if (key=='z') {/* code for extra credit */}; if (key=='X') {String S="PIC"+"-####.tif"; saveFrame(S);}; }; //*** MOUSE ACTIONS (executed each time the mouse button is pressed / released ***/ void mousePressed() { }; void mouseReleased() { };