/* 15-100 D Homework #5 Dae Hong Kim daek@andrew.cmu.edu */ void setup(){ size(600, 600); smooth(); println("Homework #5"); println("Moving the initials, DHK in four different ways"); background(0); frameRate(60); // nunber of frames per second } void draw(){ noStroke(); drawUpperLeftQuadrant(); drawLowerLeftQuadrant(); drawUpperRightQuadrant(); drawLowerRightQuadrant(); } void drawUpperLeftQuadrant(){ float initialWidth = width/20*3; // initialWidth <= the total width of all three initials float initialHeight = height/20; // initialHeight <= the height of the initials fill(255, 0, 0); noStroke(); rect(0, 0, width/2, height/2); drawInitials((frameCount%(width/2 + initialWidth)) - initialWidth, height/6, initialWidth/3, initialHeight); drawInitials((width/2 + initialWidth) - frameCount%(width/2 + initialWidth) - initialWidth, height/3, initialWidth/3, initialHeight); } void drawLowerLeftQuadrant(){ float initialWidth = width/20*3; float initialHeight = height/20; fill(0, 255, 0); noStroke(); rect(0, height/2, width/2, height); drawInitials(width/20, ((frameCount%(height/2 - initialHeight))) + height/2, initialWidth/3, initialHeight); drawInitials(width/3.5, ((height/2 - initialHeight) - (frameCount%(height/2 - initialHeight))) + height/2, initialWidth/3, initialHeight); } void drawUpperRightQuadrant(){ float initialWidth = width/20*3; float initialHeight = height/20; fill(0, 0, 255); noStroke(); rect(width/2, 0, width, height/2); drawInitials((frameCount%(width/2 - initialWidth)) + width/2, frameCount%(height/2 - initialHeight), initialWidth/3, initialHeight); drawInitials(((width/2 - initialWidth) - (frameCount%(width/2 - initialWidth))) + width/2, frameCount%(height/2 - initialHeight), initialWidth/3, initialHeight); } void drawLowerRightQuadrant(){ float initialWidth = width/20*3; float initialHeight = height/20; fill(100); noStroke(); rect(width/2, height/2, width, height); drawInitials((frameCount%(width/2 - initialWidth)) + width/2, ((height/2 - initialHeight) - (frameCount%(height/2 - initialHeight))) + height/2, initialWidth/3, initialHeight); drawInitials(((width/2 - initialWidth) - (frameCount%(width/2 - initialWidth))) + width/2, ((height/2 - initialHeight) - (frameCount%(height/2 - initialHeight))) + height/2, initialWidth/3, initialHeight); } // 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(); }