We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I don't know where I need to put buttons, "if (weather)" and "backgroundcolor()". If I put the buttons in setup() it wont work.
var bg;
var weather;
var toggle = '';
var f = '&units=imperial';
var c = '&units=metric';
var btnCity, city;
var btnDesc, desc;
var btnTemp, temp;
var btnSpee, spee;
// function windowResized() { //updates size
// resizeCanvas(windowWidth, windowHeight);
// }
function setup(){
var url = 'http://api.openweathermap.org/data/2.5/weather?zip=75081&appid=0a59bb3a87d56084a596f8eb5f50ee42';
url += f;
loadJSON(url, gotData);
// bg = createCanvas(windowWidth, windowHeight); //changes so put it in draw()
// bg.position(0, 0); //need this to overlap with html
// bg.style('z-index', '-1'); //css
btnCity = createButton(city);
btnDesc = createButton('weather.weather[0].description');
btnTemp = createButton('weather.main.temp');
btnSpee = createButton('weather.wind.speed');
}
function gotData(data) { //gets JSON data from API
weather = data; //store data in var to prevent time dilation?
// console.log(weather); //JSON
}
function draw() {
if (weather) { //wait until JSON is loaded
city = weather.name;
// btnDesc = createButton(weather.weather[0].description);
// btnTemp = createButton(weather.main.temp + ' F');
// btnSpee = createButton(weather.wind.speed + ' mph');
}
}
Answers
https://p5js.org/reference/#/p5/preload
https://p5js.org/reference/#/p5/loadJSON
That helped, GoToLoop. I am starting over.
I am trying to simplify it as much as possible. Can you help me fix my temperature button?
http://Bl.ocks.org/GoSubRoutine/5fbc03e019c53254a2ba7e7fd3318b45
@GoToLoop Trying out a new js editor?
Kf
I've already mentioned the Gist.GitHub.com + Bl.ocks.org combo in your forum thread: L-)
https://forum.Processing.org/two/discussion/22191/trying-loading-media-in-thimbleproject#Item_5
Actually I've typed in all of it in NotePad2 text editor and run it locally as
file:///
schme: ;;)https://xhmikosr.GitHub.io/notepad2-mod/
I got my bottoms to work but I have to click on it couple times for some reason. I know redraw() doesnt work well in draw(). Maybe it is the same with loop().
My html/ body does not show. I have 4 buttons with id city, desc, temp, and spee.
I gotta go to work right now but I will try rearranging my code when I am free.
loop() is opposite to noLoop(). You call the latter in setup. This means draw runs once and stops. Then, when you call loop(), draw will begin executing 30 fps again. Technically you just need to call it once.
By the way, you don't use redraw in draw. You use redraw to trigger running draw. But if you call it from draw, you will need to call redraw once outside draw for the redraw inside draw to execute. It is not complicated but I have a feeling it is not what you want in your program. At least not redraw inside draw. Maybe redraw instead of loop in your call back functions?
Kf
Thanks guys. I manage to simplify my code as much as possible. Here is what I have right now. It is for a freecodecamp challenge: