Skip to content

Instantly share code, notes, and snippets.

@hiroto3432
Last active July 1, 2018 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hiroto3432/95d733118d8f8eadc42a9f17a85d413b to your computer and use it in GitHub Desktop.
Save hiroto3432/95d733118d8f8eadc42a9f17a85d413b to your computer and use it in GitHub Desktop.
String URL = "http://weather.livedoor.com/forecast/webservice/json/v1?city=170010";
String title,date,time;
JSONArray forecasts;
void setup(){
size(300,300);
loadJson();
int fontSize = 20;
PFont font = createFont("MS-Mincho.vlw",fontSize);
textFont(font);
textAlign(CENTER,CENTER);
imageMode(CENTER);
textLeading(fontSize+5);
}
void loadJson(){
try{
JSONObject jobj = loadJSONObject(URL);
title = jobj.getString("title");
String ptime = jobj.getString("publicTime");
date = ptime.substring(0,10);
time = ptime.substring(11,19);
forecasts = jobj.getJSONArray("forecasts");
}catch(Exception e){
e.printStackTrace();
exit();
}
}
void draw(){
background(255);
fill(0);
text(title,width/2,30);
text(date+" "+time, 180,55);
for(int i = 0; i < forecasts.size(); i++){
JSONObject f = forecasts.getJSONObject(i);
String s = f.getString("dateLabel") + "\n" + f.getString("telop");
JSONObject t = f.getJSONObject("temperature");
if(!t.isNull("min")){
String d = t.getJSONObject("min").getString("celsius");
s = s + "\n min:" + d;
}
if(!t.isNull("max")){
String d = t.getJSONObject("max").getString("celsius");
s = s + "\n max:" + d;
}
JSONObject im = f.getJSONObject("image");
String imURL = im.getString("url");
PImage img = loadImage(imURL);
fill(255);
rect(30 + 80 * i,100,80,160);
fill(0);
image(img,70 + 80 * i,130);
text(s, 70 + 80 * i, 200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment