import java.util.Random; import java.util.ArrayList; PShape usa; PShape state; Random r; String [] states = { "HI", "RI", "CT", "MA", "ME", "NH", "VT", "NJ", "FL", "NC", "OH", "IN", "IA", "CO", "NV", "PA", "DE", "MD", "MI", "WA", "CA", "OR", "IL", "MN", "WI", "DC", "NM", "VA", "AK", "GA", "AL", "TN", "WV", "KY", "SC", "NY", "WY", "MT", "ID", "TX", "AZ", "UT", "ND", "SD", "NE", "MS", "MO", "AR", "OK", "KS", "LA", }; ArrayList Obama; ArrayList McCain; int ClickCount; void setup() { size(950, 800); usa = loadShape("Blank_US_Map.svg"); ClickCount = 0; smooth(); //noLoop(); } void draw() { background(255); // Draw the full map shape(usa, 0, 0); if(ClickCount > 0) { // Blue denotes states won by Obama statesColoring((String[])Obama.toArray(new String[] { }) , color(0, 51, 102)); // Red denotes states won by McCain statesColoring((String[])McCain.toArray(new String[] { }), color(153, 0, 0)); } // Save the map as image //saveFrame("map output.png"); } void statesColoring(String[] data, int c){ for (int i = 0; i < data.length; ++i) { PShape state = usa.getChild(data[i]); // Disable the colors found in the SVG file state.disableStyle(); // Set our own coloring fill(c); noStroke(); // Draw a single state shape(state, 0, 0); } } void mouseClicked() { ClickCount++; println("Clicked!"); r = new Random(); Obama = new ArrayList(); McCain = new ArrayList(); for (int i = 0; i < 51; i++) { if (r.nextBoolean()) { Obama.add(states[i]); } else { McCain.add(states[i]); } } }