int num=20; float[] sdr=new float[num]; int many= sdr.length; int firstX=10, firstY=40, SPACING=11; int nextX, nextY, wbig; float big, multiplier; void setup() { size(600, 480); scene(); smooth(); frameRate(30); int wbig=-1; fillSDR(); } void scene() { int x = width/2; int y = height/2; background(0); fill(80); rectMode(CENTER); rect(x, y-15, 589, 422); fill(20, 170, 200); text("Array Filled : ", x+70, 30); text("Array Sorted : ", x+70, 50); text("Greatest Value : ", x+70, 70); text("PROJECT 5: Array #Samuel Roman", 5, 475); fill(255); text("Press F Key to Fill Array", x+40, 320); text("Press S Key to Sory Array", x+40, 340); text("Press B key to find Biggest number",x+40,360); text("Press M key to Send Biggest to End", x+40, 380); text("Press N Key to Send 2nd Biggest to End", x+40, 400); } void draw() { showBig(); // for loop show(); // show all } void keyPressed() { if (key == 'f') { // fill array int wbig=-1; scene(); fillSDR(); // for loop* show(sdr, many); fill(0, 255, 0); text("Process complete", 453, 30); } if (key == 'b') { scene(); show(sdr, many); showBig(); // find big println("Biggest :"+big); fill(0, 255, 0); // output greatest text(big, 475, 70); } if (key == 's') { // sort array scene(); for (int i=many;i>1;i--) { // find greatest int k = wbig(sdr, i); swap( sdr, k, i-1); // move greatest to end then shrink } show(sdr, many); // update & show array fill(0, 255, 0); text("Process complete", 460, 50); } if (key == 'm') { scene(); bigEnd(sdr, many); // find biggest && send to end show(sdr, many); // update && show sarray fill(0, 255, 0); text("Biggest SENT to END", 370, 90); } if (key == 'n') { scene(); for (int i=many; i>1; i=0) { // find second biggest int k= wbig(sdr, i-1); swap(sdr, k, i-2); // swap to 2nd spot before end } show(sdr, many); // update && show array fill(0, 255, 0); text("2nd Biggest SENT to END", 360, 90); } /* if (key == 'd') { int dub=sdr.sort(); scene(); */ } void fillSDR() { // fill array random int from 0-100 for (int i=0; i1;i--) { // find greatest int k = wbig(sdr, i); swap( sdr, k, i-1); // move greatest to end then shrink } show(sdr, many); // update && show array } void bigEnd(float[] sdr, int many) { // send big to end for (int i=many; i>1;i=0) { int k= wbig(sdr, i); // biggest swap(sdr, k, i-1); // swap to end } show(sdr, many); // update && show array } void swap(float[] sdr, int k, int i) { // swap 2 elements of an array float tmp; tmp= sdr[k]; sdr[k] = sdr[i]; sdr[i] = tmp; } int wbig(float[] sdr, int many) { // where the biggest number is int w=0; for (int j=1; j sdr[w]) w=j; } return w; } void show(float[] sdr, int many) { nextX=firstX; nextY=firstY; int k= wbig(sdr, many); big= sdr[k]; // new biggest in array multiplier= (width-370) / big; // bar length && display scene(); for (int i=0;i big) big= sdr[j]; } }