import processing.opengl.*; // using openGL improves texture quality and performance // CS3451 // Project P01: 3-D animation of text and textured polygon // Written by Derek Tatum August 26-28, 2008 PImage myImage; // variable referencing image for texture String name="Derek Tatum"; // string containing name to be rendered float w = 1; // desired size of image in the final picture float tm=100, t=tm, spin=0, rotatin=3, alreadyReleased=0, rotatinSlowDown=0, atAnimation2=0, getCentered=0,atTextAnimation2=0, goRight=1, goUp=1, rotatinText=1; float x=0,y=0,textX,textY;// mouse controlled variables boolean first=true; //int print=0; 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("Derek.jpg"); // load image for texture (file in the Data folder) textureMode(NORMALIZED); // texture parameters in [0,1]x[0,1] imageMode(CENTER); 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--; if (spin<3 && t==0){ t=tm; spin++; } } if (w<300) w+=1; else w=300; 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;rotatinSlowDown=0;rotatin=3;getCentered=0;textX=x; textY=y; rotatinText=1;}; if (mousePressed && atAnimation2==0 && atTextAnimation2==0) {t=tm; w=1;spin=0;first=true;rotatinSlowDown=0;rotatin=3;getCentered=0;alreadyReleased=0;atAnimation2=0;atTextAnimation2=0;} if (mousePressed && atAnimation2==1 && atTextAnimation2==1) { alreadyReleased=1;}// change parameters for second animation. took out t=tm; }; // end draw void moveImage1() { pushMatrix(); translate(width/2, height/2); // 2D translation rotateZ(t*TWO_PI/tm); scale(w); // uniform scale renderImage(); popMatrix(); } void moveText1() { pushMatrix(); translate(width/4, height-130); // 2D translation rotateX(TWO_PI*t/tm); renderText(); popMatrix(); } void imageSpinningDoor(){ pushMatrix(); getCentered+=.005; if (getCentered<1){ translate((x-width/2),(y-height/2),0);t=100;} if (getCentered>=1){ translate(t*(x-width/2)/tm,t*(y-height/2)/tm,0);} translate(width/2, height/2); // 2D translation //println("hi"); rotateY(rotatin*TWO_PI/tm); scale(w); // uniform scale renderImage(); popMatrix(); if(rotatinSlowDown==0)rotatin+=1; if(rotatinSlowDown==1)rotatin+=.8; if(rotatinSlowDown==2)rotatin+=.60; if(rotatinSlowDown==3)rotatin+=.25; if(rotatinSlowDown==4)rotatin+=0; if(rotatin>220) rotatinSlowDown=1;// rotatin=1; if(rotatin>276) rotatinSlowDown=2;// rotatin=1; if(rotatin>290) rotatinSlowDown=3;// rotatin=1; if(rotatin>=300) {rotatinSlowDown=4; rotatin=300;}// rotatin=1; //println(rotatin); } void moveImage2() { atAnimation2 = 1; if (mousePressed==false && alreadyReleased==1){ imageSpinningDoor(); } else{ println("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 //rotateX(TWO_PI*t/tm); scale(w); // uniform scale renderImage(); popMatrix(); } } void bouncingText(){ pushMatrix(); if((textX)>=0 && (textX)<=600 && goRight==1) { textX+=8; goRight=1;} if((textX)>600 && goRight==1) { textX-=8; goRight=0;} if((textX)<0 && goRight==1) { textX+=8;} // if((textX)>=0 && (textX)<=600 && goRight==0) { textX-=8;} if((textX)<0 && goRight==0) { textX+=8; goRight=1;} if((textX)>600 && goRight==0) { textX-=8;} //println(goRight); if((textY+180)>=0 && (textY+180)<=600 && goUp==1) { textY+=8; goUp=1;} if((textY+180)>600 && goUp==1) { textY-=8; goUp=0;} if((textY+180)<0 && goUp==1) { textY+=8;} // if((textY+180)>=0 && (textY+180)<=600 && goUp==0) { textY-=8;} if((textY+180)<0 && goUp==0) { textY+=8; goUp=1;} if((textY+180)>600 && goUp==0) { textY-=8;} //println(goUp); if (getCentered<1){translate((textX-width/2),(textY-height/2),0);} if (getCentered>=1){translate(t*(textX-width/2)/tm,t*((textY-height/2)-0)/tm,0);} translate(width/4, height-130); // 2D translation if (getCentered>=.7 && rotatinSlowDown!=4){rotateX((rotatinText*TWO_PI)/tm); rotatinText+=1.9;} renderText(); popMatrix(); } void moveText2() { atTextAnimation2 = 1; if (mousePressed==false && alreadyReleased==1){ bouncingText(); } else{ pushMatrix(); translate(t*(x-width/2)/tm,t*((y-height/2)-0)/tm,0); //if (textX<590) textX++; else textX=590; //rotateY(2.0*TWO_PI*x*t/tm/width); translate(width/4, height-130); // 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(-.5,-.5,0,0);//top_left vertex(.5,-.5,1,0);//top_right vertex(.5,.5,1,1);//bottom_right vertex(-.5,.5,0,1); //bottom_left; 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; w=1;spin=0;first=true;rotatinSlowDown=0;rotatin=3;getCentered=0;alreadyReleased=0;atAnimation2=0;atTextAnimation2=0;}; // 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() { };