// Homework 8 // Name: Dae Hong Kim // Section: D // E-Mail: daek@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; float baseLine; PFont f1; void setup( ) { size( 500, 300 ); background( 0, 0, 255); f1 = loadFont("f1.vlw"); textFont( f1 ); fill( 255 ); horizontalScale = width/(yValues.length+1); stroke(255, 0, 0); baseLine = height*0.8; line(0, baseLine, width, baseLine); // call your methods here drawPoints(); drawLines(); findHighest(); findLowest(); findPlain(); fill(255); text("Total Rise of the graph is " + totalRise(), width*0.05, height*0.95); text("Total Fall of the graph is " + totalFall(), width*0.6, height*0.95); }//end of setup() // Define your methods here int totalFall() { int totalSum = 0; for(int i=1; i yValues[i-1]) { totalSum += yValues[i] - yValues[i-1]; } } return totalSum; }// end of totalRise() void drawPoints() { int xPos = horizontalScale; noStroke(); for(int i=0; i< yValues.length; i++) { fill(200, 200, 0); ellipse(xPos, baseLine-yValues[i], 5, 5); fill(255); text(yValues[i], xPos-5, (baseLine-yValues[i]+15)); xPos += horizontalScale; } }//end of drawPoints() void drawLines() { int xPos = horizontalScale; stroke(255, 0, 0); for(int i=0; i< yValues.length-1; i++) { line(xPos, baseLine-yValues[i], xPos+horizontalScale, baseLine-yValues[i+1]); xPos += horizontalScale; } }//end of drawLines() void findHighest() { int highIndex = 0; for(int i=1; i yValues[highIndex]) { highIndex = i; } }//end of for drawFlag(highIndex, #00FF00); // println("HighTemp: " + highTemp + ", and the values: " + yValues[highTemp]); }//end of findHighest() void findLowest() { int lowIndex = 0; for(int i=1; i