xxxxxxxxxx
86
let json;
let temperature = 0;
let windSpeed = 0;
let mappedTemperature = 0;
let mappedWindSpeed = 0;
function preload() {
let url = "https://api.openweathermap.org/data/2.5/weather?q=chicago&units=imperial&APPID=e812164ca05ed9e0344b89ebe273c141";
json = loadJSON(url);
}
function setup() {
createCanvas(500, 500);
temperature = json.main.temp;
//temperature = 30;
// speed of animated elements
windSpeed = json.wind.speed;
//mappedTemperature = 100;
mappedTemperature = map(temperature, -10, 110, 0, 255);
mappedWindSpeed = map(windSpeed, 0, 30, 0, 255);
console.log(mappedTemperature + " " + mappedWindSpeed);
}
function draw() {
//background(255);
background(mappedTemperature, 0, 255-mappedTemperature);
fill(0);
// Display all the stuff we want to display
text("Current temperature: " + temperature, 10, 70);
text("Current wind speed: " + windSpeed, 10, 100);
}
/*
{
"coord":{
"lon":-74.01,
"lat":40.71
},
"sys":{
"message":0.2012,
"country":"US",
"sunrise":1406540974,
"sunset":1406592927
},
"weather":[
{
"id":801,
"main":"Clouds",
"description":"few clouds",
"icon":"02d"
}
],
"base":"cmc stations",
"main":{
"temp":73.45,
"humidity":83,
"pressure":999,
"temp_min":70,
"temp_max":75.99
},
"wind":{
"speed":4.45,
"gust":3.6,
"deg":259
},
"rain":{
"3h":0
},
"clouds":{
"all":24
},
"dt":1406559145,
"id":5128581,
"name":"New York",
"cod":200
}
*/