Skip to content

Instantly share code, notes, and snippets.

@andysmithfal
Created May 14, 2014 20:41
Show Gist options
  • Save andysmithfal/09bc5180f54788a0bc4f to your computer and use it in GitHub Desktop.
Save andysmithfal/09bc5180f54788a0bc4f to your computer and use it in GitHub Desktop.
Open weather map json in Processing
JSONObject json;
//options - change these!
String location = "Falmouth,UK";
int refreshInterval = 5;
//static vars - don't change!
String weatherURL = "http://api.openweathermap.org/data/2.5/weather?units=metric&q=";
long lastRefresh = 0;
void setup(){
size(640, 360);
background(0);
textFont(createFont("Georgia", 36));
getDataAndDraw();
}
void draw(){
if(millis() > lastRefresh+(refreshInterval*1000)){
getDataAndDraw();
}
}
void getDataAndDraw(){
float red_rand = random(20,255);
background(red_rand,0,0);
json = loadJSONObject(weatherURL+location);
JSONObject weatherData = json.getJSONObject("main");
int temp = weatherData.getInt("temp");
textSize(30);
text("The temperature in "+location+" is:",50,50);
textSize(40);
text(temp+"c",50,100);
lastRefresh = millis();
}
@hdsxjtu
Copy link

hdsxjtu commented Sep 29, 2018

can't work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment