city_country_temp

Now
shows three strings on display; city, country, current temperature
Next

work with potentiometer

This slideshow requires JavaScript.


___CODE____________________________________________

import com.francisli.processing.http.*;

HttpClient client;
HttpRequest city1, city2, city3, city4, city5, city6, city7;
float temp1, temp2, temp3, temp4, temp5, temp6, temp7;
String  textCity1, textCity2, textCity3, textCity4, textCity5, textCity6, textCity7;
String  textCountry1, textCountry2, textCountry3, textCountry4, textCountry5, textCountry6, textCountry7;
String  textTemp1, textTemp2, textTemp3, textTemp4, textTemp5, textTemp6, textTemp7;

PImage bg;
PFont font, font2;
float[] x;
float[] t; //array for temperature
String[] textCity;
String[] textCountry;
String[] textTemp;
float angle;

void setup() {
size(720, 480);
noStroke();
angle =random(360);
bg=loadImage(“bgcity.jpg”);
font=loadFont(“HelveticaNeue-BoldItalic-22.vlw”);
font2=loadFont(“Helvetica-18.vlw”);
x =new float[7];
for (int i=0; i<7;i++) {
x[i]=random(width);
}
client = new HttpClient(this, “api.wunderground.com”);

city1 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/Southkorea/Seoul.json”);
city2 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/usa/Newyork.json”);
city3 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/mexico/mexico.json”);
city4 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/indonesia/jakarta.json”);
city5 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/japan/tokyo.json”);
city6 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/russia/Moscow.json”);
city7 = client.GET(“/api/3b4bb4e6f6c150fa/geolookup/conditions/forecast/q/china/guangdong/guangzhou.json”);
}

void responseReceived(HttpRequest request, HttpResponse response) {
if (response.statusCode != 200) {
println(response.statusCode + “: ” + response.statusMessage);
println(response.getContentAsString());
return;
}

JSONObject object = response.getContentAsJSONObject();
//println(object);
println(object.get(“location”).get(“city”).stringValue());
println(object.get(“location”).get(“country_name”).stringValue());
println(object.get(“current_observation”).get(“temperature_string”).stringValue());
println(object.get(“current_observation”).get(“icon_url”).stringValue());
println(object.get(“current_observation”). get(“temp_f”).floatValue());

if (request == city1) {
temp1 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity1=object.get(“location”).get(“city”).stringValue();
textCountry1=object.get(“location”).get(“country_name”).stringValue();
textTemp1=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city2) {
temp2 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity2=object.get(“location”).get(“city”).stringValue();
textCountry2=object.get(“location”).get(“country_name”).stringValue();
textTemp2=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city3) {
temp3 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity3=object.get(“location”).get(“city”).stringValue();
textCountry3=object.get(“location”).get(“country_name”).stringValue();
textTemp3=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city4) {
temp4 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity4=object.get(“location”).get(“city”).stringValue();
textCountry4=object.get(“location”).get(“country_name”).stringValue();
textTemp4=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city5) {
temp5 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity5=object.get(“location”).get(“city”).stringValue();
textCountry5=object.get(“location”).get(“country_name”).stringValue();
textTemp5=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city6) {
temp6 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity6=object.get(“location”).get(“city”).stringValue();
textCountry6=object.get(“location”).get(“country_name”).stringValue();
textTemp6=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
if (request == city7) {
temp7 =object.get(“current_observation”). get(“temp_f”).floatValue();
textCity7=object.get(“location”).get(“city”).stringValue();
textCountry7=object.get(“location”).get(“country_name”).stringValue();
textTemp7=object.get(“current_observation”).get(“temperature_string”).stringValue();
}
}

void draw() {
image(bg, 0, 0);
fill(255, 255, 0, 130);

t = new float[7];
t[0]= temp1;
t[1]= temp2;
t[2]= temp3;
t[3]= temp4;
t[4]= temp5;
t[5]= temp6;
t[6]= temp7;

textCity = new String[7];
textCity[0]=textCity1;
textCity[1]=textCity2;
textCity[2]=textCity3;
textCity[3]=textCity4;
textCity[4]=textCity5;
textCity[5]=textCity6;
textCity[6]=textCity7;

textCountry = new String[7];
textCountry[0]=textCountry1;
textCountry[1]=textCountry2;
textCountry[2]=textCountry3;
textCountry[3]=textCountry4;
textCountry[4]=textCountry5;
textCountry[5]=textCountry6;
textCountry[6]=textCountry7;

textTemp= new String[7];
textTemp[0]=textTemp1;
textTemp[1]=textTemp2;
textTemp[2]=textTemp3;
textTemp[3]=textTemp4;
textTemp[4]=textTemp5;
textTemp[5]=textTemp6;
textTemp[6]=textTemp7;

for (int i=0; i<7;i++) {
fill(255, 255, 0, 230);
ellipse(x[i], height-8/2*t[i], 3*t[i], 3*t[i]); // each bubble
x[i] = x[i] + 2*cos(radians(angle));
if ( x[i]> width+3/2*t[i]) { //make it move horizontally
x[i]=0-3/2*t[i];
}
if (x[i]<0-3/2*t[i]) {
x[i]=width+3/2*t[i];
}

if (dist(x[i], height-8/2*t[i], mouseX, mouseY)< 3/2*t[i]) { //when mouse hover it it shows what city
fill(255, 0, 150, 200);
rect(x[i], height-10/2*t[i], 150, 90);
textFont(font);
fill(255);
text(textCity[i], x[i], height-10/2*t[i], 140, 100);
textFont(font2);
fill(230);
text(textCountry[i], x[i], height-10/2*t[i]+30, 150, 100);
text(textTemp[i], x[i], height-10/2*t[i]+60, 150, 100);
}
}
}

Advertisements

Comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s