//Project 8 //Michael Chimezie ///GLOBALS/// float ballDX=3; //ball 1 float ballDY=2; float ballX =5; float ballY =5; float ballDX2=3; //ball 2 float ballDY2=2; float ballX2=200; float ballY2=100; float ballDX3= 3; //ball 3 float ballDY3= 2; float ballX3= 300; float ballY3= 50; float stickX= 3; float stickY= 2; int r1 =234 ; int g1 = 7; int b1 = 7; int r2 = 213 ; int g2 = 245; int b2 = 12; int r3 = 100; int g3 = 232; int b3 = 14; int r=0; int g=0; int b=0; void setup() { size(600, 500); background(56, 54, 252); } void draw() { display(); moveBall(); display2(); moveBall2(); display3(); moveBall3(); stick(); keyPressed(); } //Draw the ball void display() { background(56, 54, 252); stroke(0); fill(r, g, b); ellipse(ballX, ballY, 55, 55); } void moveBall() { if (ballX>width || ballX<0) { ballDX *= random(-1, -5); } if (ballY>height ||ballY<0) { ballDY *=random(-1, -5); } ballX+= ballDX; ballY+= ballDY; } //Draw the ball2 void display2() { stroke(0); fill(r, g, b); ellipse(ballX2, ballY2, 55, 55); } void moveBall2() { if (ballX2>width || ballX2<0) { ballDX2 *= random(-1, -5); } if (ballY2>height ||ballY2<0) { ballDY2 *= random(-1, -5); } ballX2+= ballDX2; ballY2+= ballDY2; } //Draw the ball3 void display3() { stroke(0); fill(r, g, b); ellipse(ballX3, ballY3, 55, 55); } void moveBall3() { if (ballX3>width || ballX3<0) { ballDX3 *= random(-1, -5); } if (ballY3>height ||ballY3<0) { ballDY3 *= random(-1, -5); } ballX3+= ballDX3; ballY3+= ballDY3; } void stick() { line( stickX, stickY, 200, 100); strokeWeight(9); fill(245, 141, 12); } void keyPressed() { if (mousePressed == true && mouseX<70 && mouseX>10 && mouseY>400 && mouseY<475) { // !!!!ALL BALLS TO YELLOW r =213 ; g = 245; b = 12; } if (mousePressed == true && mouseX<310 && mouseX>250 && mouseY>400 && mouseY<475) { // !!!!ALL BALLS TO GREEN r =100 ; g = 232; b = 14; } if (mousePressed == true && mouseX<560 && mouseX>500 && mouseY>400 && mouseY<475) { // !!!!!ALL BALLS TO RED r =234 ; g = 7; b = 7; } //rectMode(CENTER); fill(r1, g1, b1); rect(500, 400, 60, 75); fill(r1, g1, b1); text( "Red", 520, 380); fill(r2, g2, b2); rect(10, 400, 60, 75); text( "yellow!", 20, 380); fill(r3, g3, b3); rect(250, 400, 60, 75); fill(91, 219, 42); text( "green!", 260, 380); }