// Homework 8 // Aileen Craig // Section A // aacraig@andrew.cmu.edu // Global Variables int [ ] yValues = { 40, 20, 60, 70, 40, 40, 30, 80, 50, 120, 40, 80, 80, 10, 50, 70, 90 }; //int [ ] yValues = { 40, 20, 60, 70, 10, 10, 10, 80, 50, 100 }; //int [ ] yValues = { 40, 20, 60, 70, 40, 10 }; int horizontalScale; PFont f1; void setup( ) { size( 500, 300 ); background( 0, 0, 255); f1 = loadFont("f1.vlw"); textFont( f1 ); fill( 255 ); text( "The Total Rise of the graph is " , width*.06, height*.95); text( "The Total Fall of the graph is ", width*.55, height*.95); stroke( 255, 0, 0); line(0, height*.7, width, height*.7); horizontalScale = (width - 20)/yValues.length; // call your methods here drawPoints( ); writeNumbers( ); drawLines( ); findMaxValues( ); findMinValues( ); findEqualValues( ); totalRise( ); totalFall( ); } // Define your methods here void findEqualValues( ) { int x = 20; int equalValues = 0; for( int i = 0; i < yValues.length - 1; i++) { if (yValues[i] == yValues[ i + 1 ]) { drawYellowCircle( x + (horizontalScale*i), height*.7 - yValues[i]); } } } void findMinValues( ) { int x = 20; int minValues = 0; for( int i = 0; i < yValues.length; i++) { if ( yValues[i] < yValues[ minValues]) { minValues = i; } } drawRedFlag( x + horizontalScale*minValues ,height*.7 - yValues[minValues]); } void findMaxValues( ) { int x = 20; int maxValues = 0; for( int i = 0; i < yValues.length; i++) { if ( yValues[i] > yValues[ maxValues]) { maxValues = i; } } drawGreenFlag( x + horizontalScale*maxValues ,height*.7 - yValues[maxValues]); } void drawPoints( ) { int x = 20; stroke(#F2FA19); strokeWeight( 10 ); for( int i = 0; i < yValues.length; i ++) { point( x, height*.7 - yValues [i]); x = x + horizontalScale; } } void writeNumbers( ) { int x = 20; strokeWeight( 5 ); for ( int i = 0; i < yValues.length; i++) { text( yValues[ i ], x, height*.75 - yValues[i] ); x = x + horizontalScale; } } void drawLines( ) { int x = 20; strokeWeight( 2 ); stroke( 255, 0, 0); for( int i=0; i < yValues.length - 1; i++) { line( x, height*.7 - yValues[i], x + horizontalScale, height*.7 - yValues[i + 1]); x = x + horizontalScale; } } void drawGreenFlag(float x, float y ) { stroke ( 255 ); line( x, y , x , y - height*.15 ); fill( #25FA17 ); triangle( x, y - height*.15, x + width*.08, y - height*.12 , x, y - height*.08); } void drawRedFlag( float x, float y) { stroke ( 255 ); line( x, y , x , y - height*.15 ); fill( #FA171E ); triangle( x, y - height*.15, x + width*.08, y - height*.12 , x, y - height*.08); } void drawYellowCircle(float x, float y) { fill( #FAE817); ellipse( x + width*.03, y - height*.04, width*.05, height*.07); } void totalRise( ) { int sum = 0; for( int i=0; i yValues [i+1] ) { sum = sum + ( yValues[i] - yValues[i+1]); } } fill( 255 ); text( sum, width*.88, height*.95); }