float x = 50; float y = 50; float w = 700; float h = 400; //Balls Ball redBonilla, greenBonilla, blueBonilla; //Buttons Button rButton, gButton, bButton; void setup() { size(800,500); /// 3 balls redBonilla= new Ball(255,0,0); blueBonilla= new Ball(0,0,255); greenBonilla= new Ball(0,255,0); redBonilla.rballs(); blueBonilla.rballs(); greenBonilla.rballs(); ///buttons rButton= new Button(5,50,50,50); rButton.r=255; rButton.g=0; rButton.b=0; gButton= new Button(5,50,50,50); gButton.r=0; gButton.g=255; gButton.b=0; bButton= new Button(5,50*3,50,50); } void draw(){ background(167,108,34); msgs(); pooltable(); moveBalls(); drawBalls(); rButton.show(); gButton.show(); bButton.show(); } void msgs(){ //title fill(0); textSize(20); text( " Project 8" , width/2 - 50, 30); //author text(" Hugo Bonilla", 20, height -20); } void drawBalls(){ //draws balls on screen redBonilla.show(); greenBonilla.show(); blueBonilla.show(); } void moveBalls(){ redBonilla.move(); blueBonilla.move(); greenBonilla.move(); } void pooltable(){ //border stroke(9,48,129); strokeWeight(25); //table fill(60,159,219); rect(x,y,w,h); } class Ball { // billiard ball color c; float x= 75, y= 75; // ball position float dx= 5,dy= 5; // ball velocity /////CONSTRUCTORS///// Ball ( int r, int g, int b) { // set colors RGB/ red,reen,blue c= color (r ,g ,b); } Ball () { } ///METHODS/// void move(){ // moves ball.. changes dx & dy x= x + dx; y= y + dy; // MAKE BALLS COUNCE OFF WALLS if (x < 75) { dx = -dx; x = x+ dx;} if (x > 725){ dx = -dx; x = x+ dx;} if (y < 75) { dy = -dy; y = y+ dy;} if (y > 425){ dy = -dy; y = y+ dy;} } void show (){ /// draw ball fill(c); noStroke(); ellipseMode(CENTER); ellipse(x, y, 25,30); } void rballs(){ //rballs= Random Balls x= 75 + random (75); y= 75 + random (75); dx= 5 + random (5); dy= 5 + random (5); } } class Button { //Button to change balls and table int r=255, b= 255, g= 235; float bx= 10, by= 50, bw=40 , bh=50; Button ( float x, float Y, float w, float h){ bx=x; by=y; bw=w; bh=h; } // METHODS void show(){ // shows button fill(r,g,b); stroke(0); strokeWeight(1); rect(bx,by,bw,bh); } }