/* 15-100 D Homework #6 Dae Hong Kim daek@andrew.cmu.edu */ PFont myFont; PImage myPic01, myPic02; PImage errorWin; void setup() { size(600, 600); smooth(); background(255); myFont = loadFont("CenturyGothic-Bold-48.vlw"); myPic01 = loadImage("pic01.jpg"); myPic02 = loadImage("pic02.jpg"); errorWin = loadImage("errorWindow.jpg"); } // end of setup() void draw() { noStroke(); showChoicesConsWin(); // display the choices in the console window showChoicesGrphWin(); // display the choices in the graphic window if(key == 'c') // clear the screen { clearScreen(); } else if(key == 'w') // while loop demo { whileDemo(); } else if(key == 'd') // do loop demo { doDemo(); } else if(key == 'f') // for loop demo { forDemo(); } else if(frameCount > 1) { showErrorMessage(); } noLoop(); }// end of draw() void showChoicesConsWin() { println("========================================"); println(" press [c] to clear the screen"); println(" press [w] to see the while loop demo"); println(" press [d] to see the do loop demo"); println(" press [f] to see the for loop demo"); println("========================================"); }// end of showChoicesConsWin() void showChoicesGrphWin() { textFont(myFont, 12); fill(0); text("Please choose one of the following:", 10, 25); text(" *press [c] to clear the screen", 10, 45); text(" *press [w] to see the while loop demo", 10, 65); text(" *press [d] to see the do loop demo", 10, 85); text(" *press [f] to see the for loop demo", 10, 105); }//end of showChoices() void keyPressed() { loop(); }// end of keyPressed() void whileDemo() // display movie posters { int xSpacing = myPic01.width/4; float xPos = 0; while(xPos < width) { image(myPic02, xPos, (height/2)-((myPic02.height/4)*2), myPic02.width/4, myPic02.height/4); image(myPic01, xPos, (height/2)-(myPic01.height/4), myPic01.width/4, myPic01.height/4); image(myPic02, xPos, (height/2), myPic02.width/4, myPic02.height/4); image(myPic01, xPos, (height/2)+(myPic01.height/4), myPic01.width/4, myPic01.height/4); xPos += xSpacing; } }// end of whileDemo() void doDemo() // disply a clock by using sin() and cos() { int clockNum = 1; int clockSz = 180; // size of the clock float clockDegree = -60.0; do { float theta = radians(clockDegree); float posX = clockSz * cos(theta); float posY = clockSz * sin(theta); textFont(myFont, 40); fill(random(255), random(255), random(255)); text(clockNum, (width/2) + posX, (height/2) + posY); clockNum++; clockDegree += 30.0; bonusText(20, width/2, height/2); } while(clockNum < 13); } // end of doDemo() void forDemo()// display the initials { float angle = 0.0; float xSpacing = 5.7; float inc = TWO_PI/25.0; float initialWidth = width/40; float initialHeight = height/40; for(int i=0; i < 100; i += 4) { drawInitials(i * xSpacing, height*0.8 + (sin(angle)*100.0), initialWidth, initialHeight); angle = angle + inc; } bonusText(18, (100 * xSpacing)-40, (height*0.8 + (sin(angle)*100.0))+10); }// end of forDemo() void bonusText(int s, float x, float y) // bonusText(size of font, x position, y postion) { textFont(myFont, s); fill(random(255), random(255), random(255)); text("Bonus~!", x, y); }// end of bonusText() void clearScreen() { background(255); showChoicesGrphWin(); }// end of clearScreen() void showErrorMessage() { image(errorWin, width/2 - (errorWin.width/2), height/2 - (errorWin.height/2)); println("************************************************"); println("* You pressed a wrong key! Please, try again *"); println("************************************************"); }// end of showErrorMessage() // method drawInitials( x coordinate, y coordinate, width of each initial, height of each initial ) void drawInitials(float x, float y, float initialWidth, float initialHeight) { // Draw Initial D noFill(); stroke(10, 188, 100); strokeWeight(5); beginShape(); curveVertex(x, y); curveVertex(x + initialWidth * 2/10, y); curveVertex(x + initialWidth * 4/10, y + initialHeight * 2/10); curveVertex(x, y + initialHeight * 6/10); curveVertex(x + initialWidth * 3/10, y + initialHeight); curveVertex(x + initialWidth * 3/10, y + initialHeight); endShape(); beginShape(); curveVertex(x, y); curveVertex(x , y + initialHeight * 2/10 ); curveVertex(x + initialWidth * 6/10, y + initialHeight * 1/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 3/10); curveVertex(x + initialWidth * 9/10, y + initialHeight * 5/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 7/10); curveVertex(x + initialWidth * 4/10 , y + initialHeight * 8/10); curveVertex(x , y + initialHeight * 8/10 ); curveVertex(x , y + initialHeight * 8/10 ); endShape(); // Draw initial H stroke(70, 18, 170); x += initialWidth; beginShape(); curveVertex(x, y); curveVertex(x, y); curveVertex(x + initialWidth * 3/10, y + initialHeight * 2/10); curveVertex(x + initialWidth * 2/10 , y + initialHeight * 5/10 ); curveVertex(x + initialWidth * 3/10, y + initialHeight * 8/10); curveVertex(x + initialWidth * 1/10, y + initialHeight); curveVertex(x + initialWidth * 1/10, y + initialHeight); endShape(); beginShape(); curveVertex(x + initialWidth * 9/10, y); curveVertex(x + initialWidth * 9/10, y); curveVertex(x + initialWidth * 7/10, y + initialHeight * 4/10); curveVertex(x + initialWidth * 7/10, y + initialHeight * 7/10); curveVertex(x + initialWidth * 8/10, y + initialHeight); curveVertex(x + initialWidth * 8/10, y + initialHeight); endShape(); beginShape(); curveVertex(x, y + initialHeight * 6/10); curveVertex(x, y + initialHeight * 6/10); curveVertex(x + initialWidth * 2/10, y + initialHeight * 5/10); curveVertex(x + initialWidth * 4/10, y + initialHeight * 6/10); curveVertex(x + initialWidth * 6/10, y + initialHeight * 5/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 6/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 6/10); endShape(); //Draw initial K stroke(150, 90, 200); x += initialWidth; beginShape(); curveVertex(x, y); curveVertex(x + initialWidth * 2/10, y + initialHeight * 2/10); curveVertex(x + initialWidth * 3/10, y + initialHeight * 3/10); curveVertex(x + initialWidth * 2/10, y + initialHeight * 5/10); curveVertex(x, y + initialHeight * 4/10); curveVertex(x + initialWidth * 1/10, y + initialHeight * 1/10); curveVertex(x + initialWidth * 3/10, y); curveVertex(x + initialWidth * 5/10, y + initialHeight * 2/10); curveVertex(x + initialWidth * 5/10, y + initialHeight * 6/10); curveVertex(x + initialWidth * 3/10, y + initialHeight * 7/10); curveVertex(x, y + initialHeight); curveVertex(x, y + initialHeight * 8/10); curveVertex(x, y + initialHeight * 8/10); endShape(); beginShape(); curveVertex(x + initialWidth, y); curveVertex(x + initialWidth, y); curveVertex(x + initialWidth * 7/10, y + initialHeight * 6/10); curveVertex(x + initialWidth * 5/10, y + initialHeight * 5/10); curveVertex(x + initialWidth * 6/10, y + initialHeight * 3/10); curveVertex(x + initialWidth * 8/10, y + initialHeight); curveVertex(x + initialWidth, y + initialHeight * 9/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 8/10); curveVertex(x + initialWidth * 8/10, y + initialHeight * 8/10); endShape(); }// end of drawInitials()