Get the current weather information. The URL returns a JSON file with different information. Many online API's exist; this is just one example. The JSON has the following params:
main.temp
main.feels_like
main.temp_min
main.temp_max
main.pressure
main.humidity
visibility
wind.speed
wind.deg
clouds.all
sys.country
sys.sunrise
sys.sunset
name
Go to https://openweathermap.org/ for more information.
Before the setup function
let weatherData;
In the setup function
weatherData = await getData("https://api.openweathermap.org/data/2.5/weather?q=roskilde,dk&APPID=d28e0b6cfa6d48a373d2359ff966fbad&units=metric");
In the draw function
if (weatherData != undefined) {
text(weatherData.name + ", " + weatherData.sys.country +": " +
weatherData.main.temp +
"℃",
70,
150
);
}
let canvas;
let energyData;
async function setup() {
canvas = createCanvas(windowWidth, windowHeight);
await pSetup();
let url = "https://api.energidataservice.dk/dataset/Elspotprices?limit=24&filter={%22PriceArea%22:%22DK2%22}";
energyData = await loadJSON(url);
}
async function draw() {
background(255);
let counter = 0;
// circle
for (var i = 0; i < 24; i++) {
var x = cos(radians((360 / 24) * i+270)) * 60;
var y = sin(radians((360 / 24) * i+270)) * 60;
var rate = energyData.records[i].SpotPriceDKK / 4000;
noStroke();
fill(255 * rate, 255 - 255 * rate, 0, 200);
ellipse(x + 250, y + 150, rate * 40, rate * 40);
// current hour
var hour = new Date().getHours()%12;
var xh = cos(radians((360 / 12) *(hour)-90)) * 60;
var yh = sin(radians((360 / 12) * (hour)-90)) * 60;
noFill();
stroke(255,0,0);
ellipse(xh+250,yh+150,40,40);
}
for (const key in energyData.records) {
fill(0);
textSize(20);
noStroke();
text(energyData.records[key].HourDK, 70, 250 + counter * 20);
text(energyData.records[key].SpotPriceDKK, 340, 250 + counter * 20);
counter = counter + 1;
}
}
function keyPressed() {
if (key == "f") {
fullScreenToggle();
}
}