// HW6 // Put the required comments below: // Jennifer Shin // Section D // jshin1@andrew.cmu.edu // Copyright © Jennifer Shin March 2011 Pittsburgh, PA 15221 All Rights Reserved // Becky Berk // Vishal Agrawal PImage p; float [ ] b1 = { 29.9, 17.4, 3.0, 25.7, 5.8, 48.4 }; float [ ] b2 = { 20.14, 33.13, 3.42, 40.75, 2.37, 50.97 }; float [ ] b3 = { 41.2, 36.4, 7.5, 10.6, 4.3, 19.8 }; float [ ] b4 = { 43.1, 35.07, 9.02, 10.96, 1.58, 19.78 }; float [ ] b5= { 54.4, 17.4, 9.4, 14.7, 4.1, 27.2 }; float [ ] b6 = { 54.19, 15.54, 11.03, 16.58, 2.31, 25.36 }; float [ ] b7 = { 44.1, 20, 17.6, 12.3, 6.1, 25 }; float [ ] b8 = { 45.19, 19.19, 21.17, 12.1, 1.92, 26.51 }; float [ ] b9 = { 77.6, 9.7, 5.7, 4.3, 2.7, 12.1 }; float [ ] b10 = { 74.75, 10.01, 7.40, 5.82, 1.81, 14.91 }; int z; void setup ( ) { size ( 700, 650 ); p = loadImage ( "p.gif" ); image ( p, 0, 0, width, height ); textSize ( 14 ); fill ( #225FC6 ); text ( "click here for Bronx", .6*width, .2*height ); text ( "click here for Manhattan", .32*width, .35*height ); text ( "click here for Queens", .7*width, .5*height ); text ( "click here for Brooklyn", .48*width, .66*height ); text ( "click here for Staten Island", .1*width, .815*height ); text ( "http://www.citymapnewyork.com/wp-content/uploads/2010/11/new-york-city-boroughs-map.gif", .15*width, .98*height); stats ( ); z = 225; } void draw ( ) { clickHover ( ); } void clickHover ( ) { textSize ( 14 ); if (mousePressed == true ) { if (mouseX >=.6*width && mouseX <=.775*width && mouseY <=.2*height && mouseY >=.185*height ) { noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height, .15*width, .2*height ); noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height + z, .1*width, .2*height ); bronxStats ( b1 ); bronxStats2 ( b2 ); } else if (mouseX>=.48*width &&mouseX <=.68*width &&mouseY <=.66*height && mouseY >=.645*height) { noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height, .15*width, .2*height ); noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height + z, .1*width, .2*height ); bronxStats ( b3 ); bronxStats2 ( b4 ); } else if (mouseX >=.32*width && mouseX <=.535*width &&mouseY<=.35*height && mouseY>=.335*height) { noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height, .15*width, .2*height ); noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height + z, .1*width, .2*height ); bronxStats ( b5 ); bronxStats2 ( b6 ); } else if (mouseX >=.7*width && mouseX<=.88*width &&mouseY <=.5*height && mouseY>=.485*height ) { noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height, .15*width, .2*height ); noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height + z, .1*width, .2*height ); bronxStats ( b7 ); bronxStats2 ( b8 ); } else if (mouseX>=.1*width && mouseX <=.335*width && mouseY<=.815*height && mouseY>=.8*height) { noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height, .15*width, .2*height ); noStroke ( ); fill ( 255 ); rect ( .28 * width, .035*height + z, .1*width, .2*height ); bronxStats ( b9 ); bronxStats2 ( b10 ); } } } void stats ( ) { fill ( #05A9FF ); text ( "2000 DEMOGRAPHICS (in %): ", 20, 20 ); text ( "Whites: ", 20, 40 ); text ( "Black or African American: ", 20, 60 ); text ( "Asian: ", 20, 80 ); text ( "Some other race: ", 20, 100 ); text ( "Mixed race: ", 20, 120 ); text ( "Hispanic or Latino: ", 20, 140 ); text ( "2006 DEMOGRAPHICS (in %): ", 20, 225 ); text ( "Whites: ", 20, 225 + 40 ); text ( "Black or African American: ", 20, 60 + 225 ); text ( "Asian: ", 20, 80 + 225 ); text ( "Some other race: ", 20, 100 + 225 ); text ( "Mixed race: ", 20, 120 + 225 ); text ( "Hispanic or Latino: ", 20, 140 +225 ); } void bronxStats ( float [ ] b ) { fill ( #05A9FF ); int x=40; for ( int i = 0; i < b.length; i++ ) { text ( b[i], .28*width, x ); x = x+20; } } void bronxStats2 ( float [ ] b ) { fill ( #05A9FF ); float x = 247.75; int y = 20; text ( b[0], .28*width, x + y ); text ( b[1], .28*width, x + 2*y); text ( b[2], .28*width, x + 3*y); text ( b[3], .28*width, x + 4*y); text ( b[4], .28*width, x + 5*y); text ( b[5], .28*width, x + 6*y); } //void keyPressed( ) //{ // if ( key == 'j') // { // saveFrame("HW8.jpg"); // } //} //http://www.nycgo.com/?event=view.article&id=78912 //http://factfinder.census.gov/servlet/GCTTable?_bm=y&-geo_id=04000US36&-ds_name=DEC_2000_SF1_U&-_lang=en&-redoLog=false&-format=ST-2&-mt_name=DEC_2000_SF1_U_GCTP6_ST2&-CONTEXT=gct