Created
May 14, 2014 20:41
-
-
Save andysmithfal/09bc5180f54788a0bc4f to your computer and use it in GitHub Desktop.
Open weather map json in Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can't work