xxxxxxxxxx
59
var weather
var currenttemp
var tempcolour
var loc
var loclat
var currentloc
var url
lapistart ='https://api.openweathermap.org/data/2.5/weather?q=';
lapiend ='&exclude=hourly,daily&units=metric&appid=8ffe55f11a95b5201fb8ab538c365a4e';
function setup(){
createCanvas(windowWidth,windowHeight);
colorMode(HSB,360,100,100);
input = createInput();
input.position(20, 65);
button = createButton('submit');
button.position(input.x + input.width, 65);
button.mousePressed(loc);
place = createElement('h2', 'what is your location?');
place.position(20, 5);
}
function loc() {
place.html('Welcome to ' + input.value() + ' here are your weather stats:');
url=lapistart + input.value() + lapiend;
loadJSON(url,gotData);
}
function gotData(data){
weather = data;
currenttemp = weather.main.temp +'Cº';
tempcolour= 200+3.2*(weather.main.temp+15);
}
function draw(){
background(100);
print(url);
print(input.value());
if(weather){
fill(tempcolour, 100, 100);
noStroke();
ellipse(width/2,height/2,width/2,height/2);
fill(0,0,0);
textSize(40);
textAlign(CENTER,CENTER);
text(currenttemp,width/2,height/2);
text(currentloc,width/2,height/3);
}
}