// Yennifer Tejada // project 8 int size = 50; float r; float g; float b; // declare the objects from the class Ball redTejada; Ball greenTejada; Ball blueTejada; Ball randomTejada; //Button Button[] buttons = new Button[4]; // setup for the output window void setup() { size(700, 600); r = random(255); g = random(255); b = random(255); // the three different balls redTejada = new Ball(30); greenTejada = new Ball(35); blueTejada = new Ball(25); randomTejada = new Ball(20); // the different buttons loop for(int i = 0; i < buttons.length; i++) { buttons[i] = new Button(i*90+25,height /2 + 230, 60,30); } } // draw the background void draw() { background(18, 110, 255); stroke(3); table(); redTejada.display(); redTejada.moveHorizontal(); redTejada.moveVertical(); greenTejada.display(); greenTejada.moveHorizontal(); greenTejada.moveVertical(); blueTejada.display(); blueTejada.moveHorizontal(); blueTejada.moveVertical(); randomTejada.display(); randomTejada.moveHorizontal(); randomTejada.moveVertical(); for(int i = 0; i < buttons.length; i++) { buttons[i].display(); } textSize(15); fill(0); text("Project 8", 320, 20); text("Author: Yennifer Tejada", 30, 590); } // the pool table void table() { stroke(124, 74, 22); strokeWeight(30); //green fill(0, 137, 24); rect(60, 90, 600, 400); noStroke(); fill(0); ellipse(70, 99, 35, 35); ellipse(360, 94, 34, 34); ellipse(650, 99, 35, 35); ellipse(360, 487, 34, 34); ellipse(70, 480, 35, 35); ellipse(655, 480, 35, 35); } ///////////////////////////////BALL////////////////////////////// class Ball { // the x and y coordinates float x; float y; //the RGB colors float r; float g; float b; // the horizontal and vertical direction float speedX; float speedY; float speed; float xpos, ypos; int xdirection = 2; int ydirection = 2; float ballSize; Ball(float s) { x = width /2; y = height / 2; speedX = random(3, 6); speedY = random(3, 6); r = random(255); g = random(255); b = random(255); ballSize = s; } Ball() { x = random(width); y = random(50, height - 75); speed = random(3, 6); smooth(); } void display() { noStroke(); fill(r, g, b); ellipse(x, y, ballSize, ballSize); } void moveHorizontal() { // move the x-coordinates x = x + speedX; if (x < 80 || x > width - 80) { speedX = -speedX; } } void moveVertical() { // move the y-coordinates y = y + speedY; if (y < 120 || y > height - 140) { speedY = -speedY; } } } void keyPressed() { if (key == 'q') exit(); } /////////////////////////BUTTON/////////////////////////////// class Button { // declare the variables for the buttons float x; float y; float w; float h; // random RGB // float r; // float g; // float b; Button(float tejaX, float tejaY, float tejaW, float tejaH) { x = tejaX; y = tejaY; w = tejaW; h = tejaH; } void display() { rectMode(CORNER); fill(r,g,b); rect(x,y,w,h); } }