1.YahooWeatherライブラリの追加
まずProcessingを起動し,上のメニューバーから「スケッチ」→「ライブラリのインポート」→「ライブラリの追加」を選択。
そうしたらウィンドウが出てくるので「yahoo」と入力して,出てくるライブラリを選択して「install」をクリック。
あっという間にライブラリが追加できた。
2.プログラムを書く
ProcessingのライブラリリファレンスのサイトにYahooWetherライブラリの詳細が書かれているのでそいつを参考にして作れる。
で,とりあえず現在の状態と明日の天気を表示できた。以下ソースコード。説明はコメントに書いたのでそちらを参照のこと。WOEIDは検索すると各地域の番号が得られるのでそちらを参照のこと。
/* ライブラリのインポート */
import com.onformative.yahooweather.*;
/* 情報を受け取るためのクラス */
YahooWeather weather;
/* 更新間隔[ms] */
int updateIntervallMillis = 30000;
void setup() {
size(512, 512);
/* "Where On Earth IDentifier"という地域ごとに決められたIDのこと */
/* 東京 :1118370 */
/* 名古屋:1117817 */
/* 大阪 :15015370 */
int WOEID = 1118370;
/* cはセルシウス温度で表示するように指定したもの */
weather = new YahooWeather(this, WOEID, "c", updateIntervallMillis);
}
void draw() {
background(0);
fill(0, 255, 0);
/* 日本語が表示されない場合はフォントを変えてみてください */
textFont(createFont("メイリオ", 16));
/* 更新確認 */
weather.update();
/* 情報の表示 */
/* text(文字列,x,y)で(x,y)から文字列を表示できる */
text("市町村名: "+weather.getCityName(), 20, 16);
text("国名 : "+weather.getCountryName(), 20, 32);
text("経度 : "+weather.getLongitude()+" 緯度: "+weather.getLatitude(), 20, 48);
text("更新日時: "+weather.getLastUpdated(), 20, 64);
text("日の出 : "+weather.getSunrise(), 20, 80);
text("日の入り: "+weather.getSunset(), 20, 96);
text("*****現在の状態*****",20,128);
text("天気 : "+weather.getWeatherCondition(),20,144);
text("気温 : "+weather.getTemperature(), 20, 160);
text("風速 : "+weather.getWindSpeed(), 20, 176);
text("風の向き: "+weather.getWindDirection(), 20, 192);
text("湿度 : "+weather.getHumidity(), 20, 208);
text("気圧 : "+weather.getPressure(), 20, 224);
text("*****明日の状態*****",20,256);
text("天気 : "+weather.getWeatherConditionTomorrow(), 20, 272);
text("最低気温: "+weather.getTemperatureLowTomorrow(), 20, 288);
text("最高気温: "+weather.getTemperatureHighTomorrow(), 20, 304);
}
ProcessingをAndroid端末などで動かすこともできるらしいので,それでアプリなどを作る際には結構使えると思う。


