/*Erica D. Cochran ericac@andrew.cmu.edu Section B Copyright © Erica D. Cochran September 27, 2009 Carnegie Mellon University Exploring Programming with Graphics All Rights Reserved */ PFont f1; PFont f2; float x, y, speed, iw, ih; void setup( ) { size( 500, 500 ); smooth( ); background( 10 ); speed = 10; iw = width*.2; ih = height*.2; x = width/2.5; y = height/2.5; f1 = loadFont("f1.vlw"); f2 = loadFont("f2.vlw"); } void draw( ) { fill( 0, 10 ); rect( 0, 0, width, height ); moveInitials (); showDirections (); showSpeed (); } void drawInitials(float x, float y, float iw, float ih) { //Letter E of initials noFill(); beginShape(); strokeWeight(1); stroke(250,70,150); curveVertex(x+(.3*iw),y+(.23*ih)); curveVertex(x+(.3*iw),y+(.23*ih)); curveVertex(x+(.2*iw),y+(.167*ih)); curveVertex(x+(.05*iw),y+(.33*ih)); curveVertex(x+(.175*iw),y+(.53*ih)); curveVertex(x+(.2*iw),y+(.58*ih)); curveVertex(x+(.2*iw),y+(.58*ih)); endShape(); //midpoint beginShape(); strokeWeight(1); stroke(250,40,100); curveVertex(x+(.2*iw),y+(.58*ih)); curveVertex(x+(.2*iw),y+(.58*ih)); curveVertex(x+(.175*iw),y+(.633*ih)); curveVertex(x+(.05*iw),y+(.833*ih)); curveVertex(x+(.2*iw),(y+ih)); curveVertex(x+(.3*iw),y+(.833*ih)); curveVertex(x+(.3*iw),y+(.833*ih)); endShape(); //Letter D //Vertical part of letter beginShape(); strokeWeight(1); stroke(255,200,70); curveVertex(x+(.375*iw),y+(.167*ih)); curveVertex(x+(.375*iw),y+(.167*ih)); curveVertex(x+(.425*iw),y+(.58*ih)); curveVertex(x+(.375*iw),y+ih); curveVertex(x+(.375*iw),y+ih); endShape(); //Curved part of letter beginShape(); strokeWeight(1); stroke(25,255,10); curveVertex(x+(.375*iw),y+(.167*ih)); curveVertex(x+(.375*iw),y+(.167*ih)); curveVertex(x+(.625*iw),y+(.58*ih)); curveVertex(x+(.375*iw),y+ih); curveVertex(x+(.375*iw),y+ih); endShape(); //Letter C //Top Swirl of C beginShape(); strokeWeight(1); stroke(105,100,255); curveVertex(x+(.96*iw),y+(.26*ih)); curveVertex(x+(.96*iw),y+(.26*ih)); curveVertex(x+(.975*iw),y+(.25*ih)); curveVertex(x+(.96*iw),y+(.23*ih)); curveVertex(x+(.95*iw),y+(.26*ih)); curveVertex(x+(.975*iw),y+(.3*ih)); curveVertex((x+iw),y+(.23*ih)); curveVertex((x+iw),y+(.23*ih)); endShape(); //Big curved protion of letter C beginShape(); strokeWeight(1); stroke(15,205,255); curveVertex((x+iw),y+(.23*ih)); curveVertex((x+iw),y+(.23*ih)); curveVertex(x+(.875*iw),y+(.167*ih)); curveVertex(x+(.7*iw),y+(.58*ih)); curveVertex(x+(.875*iw),y+ih); curveVertex((x+iw),y+(.83*ih)); curveVertex((x+iw),y+(.83*ih)); endShape(); //Bottom Swirl of C beginShape(); strokeWeight(1); stroke(105,100,255); curveVertex((x+iw),y+(.83*ih)); curveVertex((x+iw),y+(.83*ih)); curveVertex(x+(.975*iw),y+(.76*ih)); curveVertex(x+(.94*iw),y+(.8*ih)); curveVertex(x+(.945*iw),y+(.83*ih)); curveVertex(x+(.97*iw),y+(.82*ih)); curveVertex(x+(.965*iw),y+(.80*ih)); curveVertex(x+(.965*iw),y+(.80*ih)); endShape(); } void keyPressed( ) { if (keyCode == UP) { y=y-speed; loop(); } else if (keyCode == DOWN) { y=y+speed; loop(); } else if (keyCode == RIGHT) { x=x+speed; loop(); } else if (keyCode == LEFT) { x=x-speed; loop(); } else if (key == 'f') { speed = speed+1; } else if (key == 's') { speed = speed-1; } else if (key == 'i') { iw = iw+1; ih = ih+1; } else if (key == 'd') { iw = iw-1; ih = ih-1; } else { showError (); } } void moveInitials () { drawInitials(x, y, iw, ih); if (x<(width-(width)) || y<(height-(height*1.025)) || x>(width-iw) || y>(height-ih)) { showWarning (); } } void showDirections () { fill (255,250,0); textFont (f1,15); text ("Arrow keys control directions", width*.32, height*.05); text ("[i] Increases Initials' Size [d] Decreases Initials' Size", width*.1, height*.9); text ("[f] Key Goes Faster [s] Key Goes Slower", width*.2, height*.95); } void showWarning () { fill (255,255,255,210); rect (width*.01, height*.01, width*.98, height*.98); fill (255,0,0); textFont(f2,60); text ("Initials Have Escaped!", width*.20, height*.5); strokeWeight (5); line (width/2, height/2, x+iw*.5, y+ih*.5); } void showError () { stroke (255,0,0); fill (0,0,255); rect(width*.01, height*.01, width*.98, height*.98); fill (255,0,0); textFont(f2,60); text ("Try Another Key!", width*.25, height*.2); noLoop(); textFont(f2,30); text ("Press an Arrow Key", width*.35, height*.3); } void showSpeed () { fill (155,150,50); textFont(f1,20); text ("Speed", width*.02, height*.05); text (speed, width*.02, height*.1); }