//matthias hopf //project 5 float[] mjh= new float[20]; float wbig; int nextX,nextY; float multiplier; final int FIRSTX=10,FIRSTY=20,SPACING=12; float big; int many=mjh.length; void setup(){size(800,480);wbig=-1;fillArray();} void draw (){ int k=whereBig(mjh, many); big=mjh[k]; multiplier=(width- (width/2)) / big; scene(); show(); if (wbig>=0){text ("the bigest value in the array is "+wbig,10,300);} } void keyPressed(){ if (key=='s'){sortArray(mjh, many);} if (key=='f'){fillArray();wbig=-1;} if (key=='b'){for (int j=0; j wbig) wbig= mjh[j];}} if (key=='m'){bigToEnd();} //if (key=='n'){} //if (key=='d'){} } void scene(){background(20,200,200);} ////makes the background void fillArray(){ for (int j=0; j<20;j++){mjh[j]=random(0,100);}} ////fills the array void show(){nextX=FIRSTX;nextY=FIRSTY;for (int j=0;jz[w]) w=j;}return w;} ////find biggest void bigToEnd(){int j=many;int k= whereBig(mjh, j);swap( mjh, k, j-1 );} ////move the biggest to the end //sort the array void sortArray( float mjh[], int many) { int j=many; // Find biggest and move it to the end. while( j>1 ) {int k= whereBig(mjh, j);swap( mjh, k, j-1 );j--;} } //draw bar void bar(float value){ float x,y,w,h; x=nextX+60; y=nextY-SPACING; w=value*multiplier; h=SPACING-2; fill(255,0,0); rectMode(CORNER); rect(x,y,w,h); fill (0); } void swap( float mjh[], int i, int j ) { //// Swap 2 elements of an array. float tmp; tmp= mjh[i]; mjh[i]= mjh[j]; mjh[j]= tmp; }