xxxxxxxxxx
60
//connect api from open weather to browser
let api = ' https://api.openweathermap.org/data/2.5/weather?q=';
let apiKey = '&appid=c3769564cbbc64204e7b3b4bfdd5969a';
let units = '&units=';
//preload images for display
//create an array of weather effect
var rain = [];
var sun = [];
var nDrops = 800;
//create variables for wind
var wSpeed =0.08;
var angle = 0.0;
var scalar = 8;
var imgWave;
function preload() {
clouds = loadImage ("Icons/cloud.png");
sunny = loadImage ("Icons/sun.png");
}
function setup() {
createCanvas(400,600);
background (0);
//gather data from openweathermap
loadJSON('https://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=c3769564cbbc64204e7b3b4bfdd5969a', gotData,'jsonp');
var button = select ('#submit');
button.mousePressed(weatherAsk);
input = select ('#city');
//prepare rain effect
for (i = 0 ; i < nDrops; i ++ ) {
rain.push(new Rain(nDrops,wSpeed));
}
}
function draw() {
background(0);
rain.forEach(function(d) {
d.drawAndDrop();
});
//wind speed
var imgWave = sin(angle)*scalar;
angle += wSpeed;
image(clouds,width/4,height*1/12-10+imgWave,width/2,height/2.2);
image(sunny,width/7,height*1/12-10+imgWave,300,400);
}