////PLEASE SEE final_holl.pde!!! //// Creating six buttons that do a variety of tasks including sort, bouncing ball, ////change background color and change random values //// File name: final_holl.pde int matt[]= new int[20]; //initializes twenty numbers color bg= color(255,243,151); // Background color. String lastClick; int avg; int countA; int countB; int countC; int countD; int countE; int countF; //creates ball Ball newball= new Ball(); //creates paramaters for all buttons Button a=new Button("A",100,20, 40, 40, 0, color(255,200,200) ); Button b=new Button("B",180,20, 40, 40, 0, color(195,255,195) ); Button c=new Button("C",260,20, 40, 40, 0, color(210,255,223) ); Button d=new Button("D",340,20, 40, 40, 0, color(255,243,180) ); Button e=new Button("E",420,20, 40, 40, 0, color(210,213,255) ); Button f=new Button("F",500,20, 40, 40, 0, color(255,223,223) ); void setup() { //// Initialize. size(640,480); //++++ ADD YOUR CODE HERE. } void draw() { //// Draw each frame: buttons at top, values at bottom + bar chart. background(bg); fill(0,0,255); text( "Matthew Holland", 10, 480 ); fill(0); text("Mean average: ", 500,10); text(avg, 600,10); //// Display array, showArray(matt, matt.length); //// Buttons. showButtons(); //// Show ball, if visible. if (newball.visible) { newball.move(); newball.show(); if (newball.isOver(mouseX,mouseY)) { newball.vanish(); } } // DEBUGGING: if (newball.visible) { text(newball.x, 600,170); text(newball.y, 600,180); } } void showButtons() { //// Show the buttons. a.show(); b.show(); c.show(); d.show(); e.show(); f.show(); } void mousePressed() { //// Check which button was clicked //changes bg color if (a.isOver(mouseX,mouseY) ) { wasClicked(a); countA++; background(0,243,151); } if (b.isOver(mouseX,mouseY) ) lastClick= "B"; { wasClicked(b); countB++; } if (c.isOver(mouseX,mouseY) ) lastClick= "C"; { wasClicked(c); countC++; } if (d.isOver(mouseX,mouseY) ) lastClick= "D"; { wasClicked(d); countD++; } if (e.isOver(mouseX,mouseY) ) lastClick= "E"; { wasClicked(e); countE++; } //draws ball and adds to f counter if (f.isOver(mouseX,mouseY) ) lastClick= "F"; { wasClicked(f); countF++; boolean visible=true; new Ball(); } } /* When a button is "clicked", perform the task described below: A: Change the background color, alternating between light-green and light-blue. B: Find the largest and smallest values in the array, and swap them. C: Replace each array element with random value (0-100) and recalculate the mean average. D: Change the array (and recalculate average): Double all values that are less than the mean average. Subtract 50 from all values that are greater than the mean average E: Change the array (and recalculate average): Add ten to all odd values in the array; Divide all odd values by three. F: Create a new ball (30 pixels diameter, randomly colored) at a random height on the left side. Ball moves diagonally (2 down, 3 right), "bouncing" off all edges of the window. Ball vanishes if it hits (or comes within a 50-pixel radius of) mouse position. */ void wasClicked( Button x ) { //// Record which button was clicked. lastClick= x.name; x.count++; } void fillArray( int matt[], int m ) { //// Fill the array with random values (0-100); for (int j=0; j0) text(count, x+20, y+h/2+10 ); } boolean isOver( int xx, int yy ) { //// Return true if xx,yy is over this button! return ( xx>x && xxy && yy0. int x,y,r=10; // Position and size of this ball. int dx=3; int dy=2; color c= color(255,0,0); ; boolean visible=false; //// METHODS() //// void create() { //// Create a ball. visible= true; //++++ ADD YOUR CODE HERE ++++ } void vanish() { //// Make the ball vanish. visible= false; } void show() { //// Show the ball, only if it is visible. if (visible) { fill (c); } } void move() { //// Move the ball. Bounce off walls. if (x>640) { dx= -dx; } else if (x<0) { dx = -dx; } if (y>480) { dy= -dy; } else if (y<0) { dy = -dy; } } boolean isOver( int xx, int yy ) { //// Return true if xx,yy is over this button! return ( xx>x && xxy && yy