xxxxxxxxxx
74
"use strict";
var particles = [];
function setup() {
createCanvas(windowWidth,windowHeight);
noStroke();
}
function draw() {
background(0);
if(frameCount%2==0){
particles.push(new Particle(random(10,45),random(30,45)));
particles.push(new Particle(random(195, 220), random(195, 220)));
}
for(var i = particles.length - 1;i > 0;i--){
var p = particles[i];
p.update();
p.display();
if(p.isOutside() || p.a <= -10){
particles.splice(i,1);
}
}
//console.log(particles.length);
}
class Particle{
constructor(vx,vy){
this.vx = vx;
this.vy = vy;
this.num = 255;
this.a = 255;
this.loc = createVector(width/2,height/2);
this.vel = createVector(0,0);
this.acc = createVector(1,1);
}
update(){
this.vel.add(this.acc);
this.loc.add(this.vel);
this.acc.mult(0);
this.vel.limit(0.05);
}
isOutside(){
if(this.loc.x < 0 ||this.loc.y>width || this.loc.y < 0 || this.loc.y >height){
return true;
}
return false;
}
display(){
this.acc = createVector(sin(radians(this.vx+this.num/2))/2,cos(radians(this.vy-this.num/2))/2);
fill(255,this.a);
var r = map(this.a,255,0,1,10);
ellipse(this.loc.x,this.loc.y,r);
this.num += map(this.a,255,0,1,0);
this.a -= 0.1;
}
}