Last active
July 1, 2018 08:36
-
-
Save hiroto3432/95d733118d8f8eadc42a9f17a85d413b to your computer and use it in GitHub Desktop.
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
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