xxxxxxxxxx
82
let url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/' + 'summary/all_day.geojson';
let loaded = false;
let earthquakeMag=0;
let earthquakeName;
let earthquakeSig;
let x = 50;
let y = 50;
function setup() {
createCanvas(720,400);
textAlign(CENTER);
background(255);
noStroke();
}
function draw() {
//background(100+earthquakeMag*20,200-earthquakeMag*20,0);
drawEarthquake();
}
function keyPressed() {
if (key == 'l') loadJSON(url, getEarthquake);
}
function getEarthquake(earthquakes) { // Geti the magnitude and name of the earthquake out of the loaded JSON
earthquakeMag = earthquakes.features[0].properties.mag;
earthquakeName = earthquakes.features[0].properties.place;
earthquakeSig = earthquakes.features[0].properties.sig;
loaded = true;
print(earthquakeMag,earthquakeName);
from = color(255, 255, 0, 0.01 * 255);
to = color(255, 80, 0, 0.1 * 255);
c1 = lerpColor(from, to, 0.26);
c2 = lerpColor(from, to, 0.16);
for (let i = 0; i < 15; i++) {
fill(from);
ellipse(
random(-40, 120), random(height),
random(-40, 120), random(height),
random(-40, 120), random(height),
random(-40, 120), random(height)
);
fill(c1);
ellipse(
random(140, 280), random(height),
random(140, 280), random(height),
random(140, 280), random(height),
random(140, 280), random(height)
);
fill(c2);
ellipse(
random(320, 480), random(height),
random(320, 480), random(height),
random(320, 480), random(height),
random(320, 580), random(height)
);
fill(to);
circle(
random(400, 560), random(height),
random(400, 560), random(height),
random(400, 560), random(height),
random(400, 560), random(height)
);
}
frameRate(10);
}
function drawEarthquake() {
if (loaded) {
stroke(.5);
circle(earthquakeSig+20,earthquakeSig+20, earthquakeMag * 10);
text(earthquakeName+"\n"+earthquakeMag, 0, height - 40, width, 30);
/*x = x + 1;
if (x > 35 && x < 100 )
{print('here ya go');
x = x + -1; }*/
noStroke();
} else text("click canvas\nuse key [l] for update", width/2, height/2);
}