Griffin Smith Assignment 5 3/14/14 The Java piece is a couple of ghosts that float around, following the mouse around the screen. The figures are white on a black screen. The ghost on the right moves slightly faster than the one on the left and her mouth closes when you click the mouse then opens up again once you click the mouse again. The ghost on the left blinks as the mouse is held down. The piece is composed of several ellipses that form the bodies, arms, eyes, and mouths of the ghosts and rectangles form the teeth and the right ghost’s open mouth. The “float” phrase establishes that the position of the mouse will affect the position of object with “x” and “y” in their coordinates. The “mousePressed” phrase allows the left ghost’s eyes to stay closed as the mouse is held down. The “int” phrase which creates the variable titled “variable” allows for the part of the right ghost’s mouth to stay closed and open, alternating with every mouse click. For both of these, the features are given the appearance of being closed by switching color from black to white. float x; // object follows mouse lateral direction float y; // object follows mouse longitudinal direction float easing = 0.005; // speed at which object follows mouse int variable = color(0); // the fill color "variable" will use this relationship int a = color(255); // the color will be white when the value is b int b = color(0); // the color will be black when the value is a void setup() { // establishes qualities of the applet size(900, 500); // establishes 900px by 500px window noStroke(); } void draw() { // begins the contents of the applet background(0); // background color is black float targetX = mouseX; // establishes that the object will follow the mouse x coordinate float dx = targetX - x; if(abs(dx) > 1) { x += dx * .05 * easing; } float targetY = mouseY; // establishes that the object will follow the mouse y coordinate float dy = targetY - y; if(abs(dy) > 1) { y += dy * .05 * easing; } fill(255); ellipse(x-30, y-30, 66, 66); // the body of the left ghost if (mousePressed) { // establishes that the next objects will be white but turn black when the mouse is pressed fill(255); } else { fill(0); } ellipse(x-20, y-30, 5, 5); // the left eye ellipse(x-40, y-30, 5, 5); // the right eye fill(0); ellipse(x-30, y-20, 10, 5); // the mouth fill(255); ellipse(x-2, y-10, 10, 10); // the right arm ellipse(x-58, y-10, 10, 10); // the left arm fill(255); rect(x-32, y-22, 4, 2); // the tooth float targetA = mouseX; // establishes that the next objects will follow the mouse x coordinate at a different speed float A = targetA - x; if(abs(A) > 1) { x += A * 11 * easing; } float targetB = mouseY; // establishes that the next objects will follow the mouse y coordinate at a different speed float B = targetB - y; if(abs(B) > 1) { y += B * 11 * easing; } fill(255); ellipse(x+45, y-30, 66, 66); // the body of the right ghost fill(0); ellipse(x+55, y-30, 5, 5); // the left eye ellipse(x+35, y-30, 5, 5); // the right eye fill(variable); // the object will use the relationship of "variable" for color rect(x+40, y-20, 10, 3); // the long part of the mouth ellipse(x+45, y-16, 10, 5); // the round botton of the mouth fill(0); rect(x+40, y-21, 10, 1); // the top line of the mouth fill(255); ellipse(x+73, y-10, 10, 10); // the right arm ellipse(x+17, y-10, 10, 10); // the left arm fill(255); rect(x+43, y-20, 4, 2); // the tooth } void mouseClicked() { if(variable==a) { variable=b; } else { variable=a; } } // the value starts at "a," but once the mouse is clicked the value changes to "b," then "a" once the mouse is clicked again