xxxxxxxxxx
55
let currentWeather;
function preload() {
// Request weather data from API
let url = 'https://api.openweathermap.org/data/2.5/group?id=4180439,4671654,4887398,4684888,5419384,4699066,5506956,5368361,4164138,5128581,5391959,5809844,4140963&units=imperial&appid=2a5cfb9dc4fb9caac3756e9908a56fa9';
// [0] Atlanta 4180439
// [1] Austin 4671654
// [2] Chicago 4887398
// [3] Dallas 4684888
// [4] Denver 5419384
// [5] Houston 4699066
// [6] Las Vegas 5506956
// [7] Los Angeles 5368361
// [8] Miami 4164138
// [9] New York City 5128581
// [10] San Francisco 5391959
// [11] Seattle 5809844
// [12] Washington, D.C. 4140963
httpGet(url, 'jsonp', false, function(response) {
currentWeather = response;
});
console.log(url);
}
function setup (){
createCanvas(550, 200);
}
function draw() {
if (!currentWeather) {
// Wait until the weather data has loaded before drawing.
return;
}
background(200);
// Pull info out of the loaded JSON
let weatherLocation = currentWeather.list[4].name;
let weatherDesc = currentWeather.list[4].weather[0].description;
let weatherTemp = currentWeather.list[4].main.temp;
textAlign(CENTER);
text(weatherLocation, 0, height - 100, width, 30);
text(weatherDesc, 0, height - 80, width, 30);
text(weatherTemp + "º F", 0, height - 60, width, 30);
noLoop();
}