// ITU Experimental Interaction, spring 2011. Mandatory Assignment #05. Jakob Fischer Jørgensen. Mail: jfis@itu.dk. // Area: String Strings, File Strings, and Internet Strings. // Theme: The lives of others. // Requirements: Sketch must access something on the internet and use it; interactive; minimum two fonts. // References: // http://weather.yahoo.com/ // http://developer.yahoo.com/weather/ // http://processing.org/discourse/yabb2/YaBB.pl?num=1250265856 // http://www.learningprocessing.com/examples/chapter-18/example-18-5/ // Basic sketch concept (refined since initial idea!): // World map, which is mouseclickable. When clicked, will display temperature where clicked. // Draws data from some kind of world weather website. // When clicked, display temperature for 2-3 seconds with font A. // Top of screen: "Click anywhere to display temperature" (or something similar) with font B. // Based on the book's Example 18-5: Parsing Yahoo's XML weather feed manually // Declare fonts PFont f1; PFont f2; PFont f3; PFont f4; // Declare our zip numbers and get a counter going so we know which city is which String[] zips = {"2459115", "455825", "615702", "1582504", "2151330", "1105779", "2351310", "3369", "1353281"}; int counter = 0; // Load our worldmap PImage worldmap; // Declare the WeatherGrabber class WeatherGrabber wg; void setup() { cursor(CROSS); size(600,400); // Make a WeatherGrabber object wg = new WeatherGrabber(zips[counter]); // Tell it to request the weather wg.requestWeather(); // Load our pre-created fonts and the worldmap image f1 = loadFont("jakobfont14.vlw"); f2 = loadFont("jakobfont12.vlw"); f3 = loadFont("jakobfont14bold.vlw"); f4 = loadFont("jakobfont11italic.vlw"); worldmap = loadImage("map.jpg"); } void draw() { // Draw the worldmap as background and display top text background(worldmap); textFont(f1); fill(0,0,0,50); text("Click a city on the world map to check out local weather!",10,15); // Draw a white ellipse for each city we can click fill(255); ellipse(164,158,20,20); // New York | 2459115 ellipse(210,260,20,20); // Rio de Janeiro | 455825 ellipse(290,130,20,20); // Paris | 615702 ellipse(310,280,20,20); // Johannesburg | 1582504 ellipse(450,170,20,20); // Beijing | 2151330 ellipse(490,300,20,20); // Sydney | 1105779 ellipse(532,305,20,20); // Wellington | 2351310 ellipse(160,130,20,20); // Ottawa | 3369 ellipse(295,167,20,20); // Tripoli | 1353281 // Change to jakobfont11italic.vlw and display city names textFont(f4); fill(0); text("New York",176,162); text("Rio de Janeiro",222,264); text("Paris",302,134); text("Johannesburg",323,284); text("Beijing",462,174); text("Sydney",499,292); text("Wellington",544,309); text("Ottawa",172,134); text("Tripoli",307,171); // Change to jakobfont12.vlw for the below textFont(f2); fill(0); // Get the values to display String weather = wg.getWeather(); int temp = wg.getTemp(); String city = wg.getCity(); // Display the weather stuff we want to display text(city,10,250); text("Current Weather: "+weather,10,390); text("Temperature: "+temp+" º C",10,370); // text(zips[counter],10,160); // text("Click to change zip." ,10,180); // Draw a little rectangular thermometer based on temperature stroke(0); fill(175); rect(10,330,temp*2,20); } // Check if we are inside a city's corresponding ellipse // If we are, set counter and grab weather based on zip void mousePressed() { if (mouseX < 174 && mouseX > 154 && mouseY < 168 && mouseY > 148) { println("New York"); counter = 0; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 220 && mouseX > 200 && mouseY < 270 && mouseY > 250) { println("Rio de Janeiro"); counter = 1; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 300 && mouseX > 280 && mouseY < 140 && mouseY > 120) { println("Paris"); counter = 2; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 320 && mouseX > 300 && mouseY < 290 && mouseY > 270) { println("Johannesburg"); counter = 3; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 460 && mouseX > 440 && mouseY < 180 && mouseY > 160) { println("Beijing"); counter = 4; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 500 && mouseX > 480 && mouseY < 310 && mouseY > 290) { println("Sydney"); counter = 5; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 542 && mouseX > 522 && mouseY < 315 && mouseY > 295) { println("Wellington"); counter = 6; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 170 && mouseX > 150 && mouseY < 140 && mouseY > 120) { println("Ottawa"); counter = 7; wg.setZip(zips[counter]); wg.requestWeather(); } else if (mouseX < 305 && mouseX > 285 && mouseY < 177 && mouseY > 157) { println("Tripoli"); counter = 8; wg.setZip(zips[counter]); wg.requestWeather(); } // else { // Increment the counter and get the weather at the next zip code // counter = (counter + 1) % zips.length; // wg.setZip(zips[counter]); // The data is requested again with a new zip code every time the mouse is pressed. // wg.requestWeather(); // } }