xxxxxxxxxx
222
let emitters = [];
let numEmitters =727;
let particleSize = 1;
let center;
let atm=600;
let table;
let numr;
let numc;
let date=[];
let avg=[];
//let sze=[];
let dataMin,dataMax=0;
let cnt=0;
function preload()
{
table = loadTable("assets/ppm.csv","csv","header");
}
function setup()
{
createCanvas(1080, 1080);
//imageMode(CENTER);
numr=table.getRowCount();
numc=table.getColumnCount();
//print(numr,numc);
for(let r=0;r<table.getRowCount();r++)
{
date[r] = table.getString(r,0);
avg[r] = table.getNum(r,1);
// print(date[r] + " " +avg[r]);
minMax();
}
center = createVector(width / 2, height / 2);
for (let i = 0; i < numEmitters; i++) {
let angle = i * (TWO_PI / numEmitters);
let pos = p5.Vector.add(center, createVector(atm/2 * cos(angle), atm/2 * sin(angle)));
emitters.push(new Emitter(pos, cnt));
cnt++;
if (cnt >= numr) {
cnt= 0;
}
} //angleMode(DEGREES);
}
function draw() {
clear();
background(25);
info();
stroke('#FFFFFF');
strokeWeight(1);
noFill();
line(0, height/2, width, 600);
line(0, height/4.2, width, 350);
line(25, height/14, width, 100);
fill(250, 170);
circle(11, height / 14,30);
circle(380,164,2);
circle(20,740,3);
circle(980,840,5);
circle(random(0,width),random(0,height),0.8);
circle(random(0,width-213),random(0,height-226,0.8));
circle(random(0,width-90),random(0,height-47),0.8);
circle(random(0,width-213),random(0,height-226,0.8));
noFill();
//rect(0,0,width,height);
strokeWeight(3);
stroke(250);
fill(250);
circle(width / 2, height / 2,atm);
stroke('#000000');
strokeWeight(4);
noFill();
circle(width / 2, height / 2,atm-200);
textAlign(CENTER);
textSize(18);
fill('#000000');
noStroke();
text("CO² PPM",width / 2, (height / 2)-24);
text("Rise",width / 2, height / 2);
text("1958 - 2018",width / 2,(height / 2)+24);
textSize(14);
stroke('#FFFFFF');
strokeWeight(1);
line(atm+260,(height / 2)+3,atm+280,(height / 2)+3);
line(atm+260,(height / 2)-9,atm+280,(height / 2)-9);
noStroke();
fill('#FFFFFF');
text("2018 - 405.51 ppm ",atm+345,(height / 2)-4);
text("1958 - 315.71 ppm ",atm+345,(height / 2)+8);
for (let emitter of emitters)
{
emitter.update();
emitter.display();
}
// orbitControl(3,3);
// for(let th=0;th<360;th+=15)
// {
// for(let ph=0;ph<360;ph+=15)
// {
// beginShape(POINTS);
// vertex(
// atm-200*sin(th)*cos(ph),
// atm-200*cos(th),
// atm-200*sin(th)*sin(ph)
// );
// endShape();
// }
// }
}
class Particle {
constructor(pos, cnt) {
this.pos = pos.copy();
this.vel = createVector();
this.acc = createVector();
this.size = particleSize;
this.alpha = map(avg[cnt], dataMin, dataMax, 150, 275);
// this.alpha = map(avg[cnt], 312.66,411.24,100,295);
}
update() {
let dir = p5.Vector.sub(center, this.pos);
dir.normalize();
dir.mult(0.01);
this.acc = dir;
this.vel.add(this.acc);
this.pos.add(this.vel);
this.alpha -=2;
this.size += 0.1;
}
display() {
noStroke();
// stroke(30);
// strokeWeight(0.3);
fill(0, this.alpha);
ellipse(this.pos.x, this.pos.y, this.size, this.size);
}
}
class Emitter {
constructor(pos, cnt) {
this.pos = pos.copy();
this.particles = [];
this.cnt = cnt;
}
update() {
if (random(1.4) < 0.02) {
this.particles.push(new Particle(this.pos, this.cnt));
}
for (let i = this.particles.length - 1; i >= 0; i--) {
let p = this.particles[i];
p.update();
if (p.alpha < 0) {
this.particles.splice(i, 1);
}
}
}
display() {
for (let particle of this.particles) {
particle.display();
}
}
}
function minMax()
{
for (let i=0;i<numr;i++)
{
if(table.getNum(i,1)>dataMax)
{
dataMax=table.getNum(i,1);
}
}
dataMin=dataMax;
for (let i=0;i<numr;i++)
{
if(table.getNum(i,1)<dataMin)
{
dataMin=table.getNum(i,1);
}
}
print(dataMin + " " + dataMax);
}
function info()
{
textSize(15);
textAlign(CENTER);
textStyle(BOLD);
fill('#FFFFFF');
text("CO² PPM - Trends in Atmospheric Carbon Dioxide.",1080/7,1080-170,1080/1.4);
//textStyle(NORMAL);
textSize(14);
text("Parts per million (ppm) is a unit of measurement used to express the concentration of a gas in the atmosphere.The concentration of CO² in the Earth's atmosphere is commonly measured in parts per million (ppm) which currently is around 414 ppm, and it has been steadily increasing since the Industrial Revolution. The increase from 1958 to 2022 is approximately 31.11% which is a significant jump since to limit the global temperature increase to 2 degrees Celsius, the CO2 concentration should be limited to 450 ppm or lower. ",100,1080-140,1080/1.2);
textSize(12);
text("Data are sourced from the US Government’s Earth System Research Laboratory, Global Monitoring Division.",1080/7,1080-40,1080/1.4);
}