//Renato Briceno - Project 5 //Defines variables sortarrays sortnum; float[] rb = new float[20]; //Defines array with 20 numbers float wbig = -1; int many = rb.length; int nextX, nextY; int FIRSTX=10, FIRSTY=height+100, SPACING=12; float big=100,multi; float textw; void setup() { size(800, 600); smooth(); frameRate(30); sortnum = new sortarrays(); // " Sortnum" class multi= (width-90)/big; textw=width-700; //Location of text sorting(); } void draw() { sortnum.scene(); sortnum.show(); instructions(); } class sortarrays { //Class "sortarrays" is defined void scene () { background(136,235,245); } void show() { nextX = FIRSTX; nextY=FIRSTY; for (int i=0; i big) big= rb[i]; } sortArray(rb,many); } void display (float v) { text ("Lagest number: " , 300,50); if (key == 'b') { //Display Biggest number when "b" is pressed fill(0); text(big,400,50);} fill(7,54,234); text(v, nextX, nextY); //Displays the array of numbers bar(v); //Bars are displayed nextY+=SPACING; } void sortArray ( float rb[],int many) { if (key == 's') { //Sorts the list when "S" is pressed int n= many; while (n>1) { int k= wbig(rb,n); swap(rb,k,n-1); // Swap function called to sort n--;} }} void swap ( float rb[], int i, int j) { float tmp; //Creates a temporary variable to swap arrays tmp= rb[i]; rb[i]= rb[j]; rb[j] = tmp; } int wbig ( float rb[], int n) { // Variable "wbig" is defined int w = 0; for (int i=1; i rb[w]) w= i; } //Returns the largest variable return w; }} void keyPressed () { if (key== 'f') { // "F" key fills the array with 20 new numbers sorting(); } } void bar(float v) { //Creates the bars { float x,y,w,h; // Local variables in order to define height, width and bar size x=nextX+60; y=nextY-SPACING; w=v*multi; h=SPACING-2; //Draw bar fill(7,54,234); rectMode(CORNER); rect(x,y,w,h); } } void sorting () { for (int i=0;i