xxxxxxxxxx
57
let weather;
let sel;
let temp;
let feelsLike;
let min;
let max;
let pressure;
let humidity;
function setup() {
createCanvas(400, 400);
background(220);
textSize(20);
text("NYC Weather!", 130, 30);
textSize(75);
loadJSON("https://api.openweathermap.org/data/2.5/weather?q=Manhattan&APPID=4854d0278ba2e81438dde1b60d215564&units=imperial", gotData);
sel = createSelect();
sel.position(137, 50);
sel.option("Temperature");
sel.option("Feels like...");
sel.option("Temp Minimum");
sel.option("Temp Maximum");
sel.option("Pressure");
sel.option("Humidity");
sel.changed(mySelect);
}
function mySelect() {
background(220);
console.log(sel.value());
if (sel.value() == "Temperature") {
text(temp + "ºF", 75, 200);
} else if (sel.value() == "Feels like...") {
text(feelsLike + "ºF", 75, 200);
} else if (sel.value() == "Temp Minimum") {
text(minimum + "ºF", 75, 200);
} else if (sel.value() == "Temp Maximum") {
text(maximum + "ºF", 75, 200);
} else if (sel.value() == "Pressure") {
text(pressure + " hPa", 40, 200);
} else {
text(humidity + "%", 140, 200);
}
}
function gotData(data) {
weather = data;
console.log(data);
temp = weather.main.temp;
feelsLike = weather.main.feels_like;
minimum = weather.main.temp_min;
maximum = weather.main.temp_max;
pressure = weather.main.pressure;
humidity = weather.main.humidity;
}