xxxxxxxxxx
//https://openprocessing.org/sketch/1186185
var weather
var city='New York';
var temp_min='=272.1';
var temp_max='=275.46';
var humidity='=79';
function setup() {
canvas = createCanvas(windowWidth, windowHeight);
canvas.background("skyblue");
textSize(50);
fill('black');
rect(75,30,900,400);
stroke(225);
//Call weather API
fetchWeather();
}
function draw() {
fill('white');
text(city, 100,100);
fill('white');
text('temp_min' + temp_min, 450, 300)
text('temp_max' + temp_max, 450, 400)
fill('white');
text('humidity' + humidity, 450, 175)
}
async function fetchWeather() {
//Get data from OpenWeather
let r = await fetch('https://api.openweathermap.org/data/2.5/weather?q=New%20York,10021&APPID=613767cfb8b84c800b878848a9b6850b');
//If call was made without an error
if (r.status === 200) {
const data = await r.text();
//Parse the json string returned from OpenWeather
var jweather = JSON.parse(data)
var jmain = JSON.parse(data)
var jname = JSON.parse('New York')
temp_min = jmain.main.temp_min
temp_max = jmain.main.temp_max
tempNow =jmain.main.temp
humidity =jmain.main.humidity
city =jname.name
}
}