import rita.*; import java.util.Random; import java.util.ArrayList; PShape usa; PShape state; Random r; RiText[] rts; RiGrammar grammar; RiText[] rtc; RiGrammar grammar2; 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", }; int [] votes = { 4, 4, 7, 12, 4, 4, 3, 15, 27, 15, 20, 11, 7, 9, 5, 21, 3, 10, 17, 11, 55, 7, 21, 10, 10, 3, 5, 13, 3, 15, 9, 11, 5, 8, 8, 31, 3, 3, 4, 34, 10, 5, 3, 3, 5, 6, 11, 6, 7, 6, 9, }; ArrayList Obama; ArrayList McCain; int dem_votes = 0; int rep_votes = 0; RiText dem_total; RiText rep_total; RiText title1; RiText title2; RiText title3; int ClickCount; String rep_candid; String dem_candid; void setup() { //950, 800 size(950, 800); usa = loadShape("Blank_US_Map.svg"); ClickCount = 0; smooth(); //Opening Title - Deleted once MouseClicked() RiText.setDefaultFont("USA_Flag-54.vlw"); title1 = new RiText(this, "Pandora Opens", 80, 220); title1.setColor(255,0,0); title2 = new RiText(this, "the Ballot Box", 80, 280); title2.setColor(0,255,0); RiText.setDefaultFont("Garamond-16.vlw"); title3 = new RiText(this, "Click to Change the Free World", width/3, 310); //Story Section rts = new RiText[3]; RiText.setDefaultAlignment(LEFT); RiText.setDefaultFont("Garamond-16.vlw"); rts[0] = new RiText(this, "", 250, 650); rts[1] = new RiText(this, "", 250, 675); rts[2] = new RiText(this, "", 250, 700); grammar = new RiGrammar(this, "elect_story.g"); //Competitors Section rtc = new RiText[3]; RiText.setDefaultAlignment(CENTER); RiText.setDefaultFont("Garamond-24.vlw"); rtc[0] = new RiText(this, "Democrats", 100, 650); rtc[1] = new RiText(this, "vs.", 115, 675); rtc[2] = new RiText(this, "Republicans", 100, 700); grammar2 = new RiGrammar(this, "elect.g"); dem_total = new RiText(this, Integer.toString(dem_votes), 200, 650); rep_total = new RiText(this, "0", 200, 700); } 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!"); RiText.delete(title1); RiText.delete(title2); RiText.delete(title3); r = new Random(); dem_votes = 0; Obama = new ArrayList(); McCain = new ArrayList(); for (int i = 0; i < 51; i++) { if (r.nextBoolean()) { Obama.add(states[i]); //println(votes[i]); dem_votes = dem_votes + votes[i]; } else { McCain.add(states[i]); } } //Story Grammar Loop rep_candid = grammar.expandFrom(""); dem_candid = grammar.expandFrom(""); String result = grammar.expand(); println(rep_candid); String[] lines = result.split("%"); for (int i = 0; i < rts.length; i++) { rts[i].fadeToText(lines[i].trim(), 1.0f); } //Competitors Grammar Loop //rtc[0].setText(dem_candid); //rtc[2].setText(rep_candid); // String result2 = grammar2.expand(); // String[] lines2 = result2.split("%"); // for (int i = 0; i < rtc.length; i++) { // rtc[i].fadeToText(lines2[i].trim(), 1.0f); // } dem_total.setText(Integer.toString(dem_votes)); rep_total.setText(Integer.toString(538 - dem_votes)); }