xxxxxxxxxx
46
//Understand API response parameters https://openweathermap.org/current
let weatherData;
function preload() {
// Let's load our json data file
// weatherData = loadJSON('newyork_weather.json');
weatherData = loadJSON('london_weather.json');
// or to load from the API:
// weatherData = loadJSON('https://api.openweathermap.org/data/2.5/weather?q=Sydney&appid=3f36a008bba9d213f7a6e6101f6588c1');
}
function setup() {
createCanvas(600, 600);
noLoop();
console.log(weatherData);
// function updateWeather() {
// weatherData = loadJSON('https://api.openweathermap.org/data/2.5/weather?q=Sydney&appid=3f36a008bba9d213f7a6e6101f6588c1');
// print('weather checked!');
// }
// setInterval(updateWeather, 5000);
}
function draw() {
background(200);
// Access weather condition data
let weather = weatherData.weather[0].main; // Clouds
let description = weatherData.weather[0].description; // overcast clouds
let temp = weatherData.main.temp; // 9.35
// Displaying the data on the canvas
textSize(16);
text('Weather: ' + weather, 10, 30);
text('Description: ' + description, 10, 50);
text('Temperature: ' + temp + '°C', 10, 70);
// For debug
print('Weather: ' + weather);
print('Description: ' + description);
print('Temperature: ' + temp + '°C');
}