xxxxxxxxxx
44
// Examples use USGS Earthquake API:
// https://earthquake.usgs.gov/fdsnws/event/1/#methods
let earthquakes;
function preload() {
// Get the most recent earthquake in the database
let url =
'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
'format=geojson&limit=1&orderby=time';
httpGet(url, 'jsonp', false, function(response) {
// when the HTTP request completes, populate the variable that holds the
// earthquake data used in the visualization.
earthquakes = response;
});
}
//CREATE A SETUP, PUT BACKGROUND IN THERE
function setup(){
createCanvas(400,400);
background(150,150,10);
//Frame rate
frameRate(10);
}
function draw() {
if (!earthquakes) {
// Wait until the earthquake data has loaded before drawing.
return;
}
// Get the magnitude and name of the earthquake out of the loaded JSON
let earthquakeMag = earthquakes.features[0].properties.mag;
let earthquakeName = earthquakes.features[0].properties.place;
//DRAW ELLIPSE RANDOMLY EACH TIME
ellipse(random(1,400), random(1,400), earthquakeMag * 10, earthquakeMag * 10);
textAlign(CENTER);
text(earthquakeName, 0, height - 30, width, 30);
//COMMENT OUT NO LOOP
//noLoop();
}