//chongho lee //section a //chonghol@andrew.cmu.edu PImage pic; PFont f1; void setup() { size( 600, 600 ); background( 255 ); pic = loadImage( "image1.gif" ); f1 = loadFont( "font1.vlw" ); } void displayErrorMessage() { println( " That was not a valid choice " ); textFont( f1, 30 ); fill(#FF0000); text( "That was not a valid choice", width*0.04, height*0.35); } void draw() { displayChoices(); //drawInitials(width/2, height/2, width*0.01, height*0.01); if ( key == 'w' ) { showWhileLoop(); } else if ( key == 'd' ) { showDoLoop(); } else if ( key == 'f' ) { showForLoop(); } else if ( key == 'c' ) { clearScreen(); } else if ( frameCount > 1 ) { displayErrorMessage(); } noLoop(); } void keyPressed() { loop(); } void clearScreen() { background( 255 ); displayChoices(); } void showForLoop() { for(int a = 0; a < width; a += 40) { drawInitials(0 + a, 0 + a, width*0.1, height*0.1); drawInitials(0 + a, (height-a)-(height*0.1), width*0.1, height*0.1); } } void showDoLoop() { int x = 0; int y = 0; textFont( f1, 30 ); fill( 0 ); do { text( " chongho ", x, y, width*0.2, height*0.2); text( " chongho ", x, (height-y)-(height*0.1), width*0.2, height*0.2); x = x+(int)(width*0.1); y = y+(int)(height*0.1); } while (x<(int)width); } void showWhileLoop() { int x = 0; int y = 0; while (x<=(int)width) { image( pic, x, y, width*0.1, height*0.1); image( pic, x, (height-y)-(height*0.1), width*0.1, height*0.1); x = x+(int)(width*0.1); y = y+(int)(height*0.1); } } void displayChoices() { println(" Enter one of the following : "); println(" [w] for a while loop demonstration "); println(" [d] for a do loop demonstration "); println(" [f] for a for loop demonstration "); println(" [c] to clear the screen "); textFont( f1, 30 ); fill( 0 ); text( " Enter one of the following : ", width*0.04, height*0.06); text( " [w] for a while loop demonstration ", width*0.04, height*0.12); text( " [d] for a do loop demonstration ", width*0.04, height*0.18); text( " [f] for a for loop demonstration ", width*0.04, height*0.24); text( " [c] to clear the screen ", width*0.04, height*0.30); } void drawInitials(float x, float y, float boxWidth, float boxHeight) { noFill(); strokeWeight(5); stroke(#EFF25F); beginShape(); curveVertex(x + .45*boxWidth, y + .45*boxHeight); curveVertex(x + .30*boxWidth, y + .30*boxHeight); curveVertex(x + .15*boxWidth, y + .15*boxHeight); curveVertex(x + .08*boxWidth, y + .25*boxHeight); curveVertex(x + .05*boxWidth, y + .50*boxHeight); curveVertex(x + .08*boxWidth, y + .75*boxHeight); curveVertex(x + .25*boxWidth, y + .85*boxHeight); curveVertex(x + .40*boxWidth, y + .70*boxHeight); curveVertex(x + .45*boxWidth, y + .60*boxHeight); endShape(); stroke(#F25F8C); beginShape(); curveVertex(x + .40*boxWidth, y + .05*boxHeight); curveVertex(x + .45*boxWidth, y + .10*boxHeight); curveVertex(x + .50*boxWidth, y + .35*boxHeight); curveVertex(x + .55*boxWidth, y + .50*boxHeight); curveVertex(x + .48*boxWidth, y + .65*boxHeight); curveVertex(x + .42*boxWidth, y + .78*boxHeight); curveVertex(x + .40*boxWidth, y + .82*boxHeight); curveVertex(x + .35*boxWidth, y + .88*boxHeight); endShape(); beginShape(); curveVertex(x + .25*boxWidth, y + .50*boxHeight); curveVertex(x + .55*boxWidth, y + .50*boxHeight); curveVertex(x + .65*boxWidth, y + .45*boxHeight); curveVertex(x + .70*boxWidth, y + .50*boxHeight); endShape(); beginShape(); curveVertex(x + .80*boxWidth, y + .05*boxHeight); curveVertex(x + .75*boxWidth, y + .10*boxHeight); curveVertex(x + .70*boxWidth, y + .35*boxHeight); curveVertex(x + .65*boxWidth, y + .50*boxHeight); curveVertex(x + .68*boxWidth, y + .65*boxHeight); curveVertex(x + .72*boxWidth, y + .78*boxHeight); curveVertex(x + .80*boxWidth, y + .82*boxHeight); curveVertex(x + .85*boxWidth, y + .88*boxHeight); endShape(); stroke(#3BFFAC); beginShape(); curveVertex(x + .85*boxWidth, y + .05*boxHeight); curveVertex(x + .90*boxWidth, y + .10*boxHeight); curveVertex(x + .93*boxWidth, y + .35*boxHeight); curveVertex(x + .95*boxWidth, y + .50*boxHeight); curveVertex(x + .92*boxWidth, y + .65*boxHeight); curveVertex(x + .88*boxWidth, y + .78*boxHeight); curveVertex(x + .84*boxWidth, y + .82*boxHeight); curveVertex(x + .80*boxWidth, y + .88*boxHeight); endShape(); beginShape(); curveVertex(x + .80*boxWidth, y + .77*boxHeight); curveVertex(x + .84*boxWidth, y + .82*boxHeight); curveVertex(x + .88*boxWidth, y + .84*boxHeight); curveVertex(x + .93*boxWidth, y + .85*boxHeight); curveVertex(x + .97*boxWidth, y + .85*boxHeight); curveVertex(x + 1.00*boxWidth, y + .84*boxHeight); curveVertex(x + 1.10*boxWidth, y + .80*boxHeight); curveVertex(x + 1.20*boxWidth, y + .72*boxHeight); endShape(); }