xxxxxxxxxx
let R = 200;
let test;
let ParticleSystem = [];
let h,s,b;
function setup() {
createCanvas(500, 500);
background(0);
colorMode(HSB,100);
h = 93//random(0,360);
s = 82//random(40,100);
b = 59//random(50,100);
//frameRate(240);
//noiseSeed(144);
for (let i=0; i<50; i++) {
let x = random(-R,R);
let y = random(-sqrt(R*R-x*x),sqrt(R*R-x*x));
ParticleSystem[i] = new Particle(0,0);
}
}
function draw() {
drawingContext.shadowBlur=0;
translate(width/2,height/2);
fill(0,0,0,5);
rectMode(CENTER);
rect(0,0,width,height);
noFill();
stroke(h,s,b,100);
strokeWeight(2);
drawingContext.shadowBlur=10;
drawingContext.shadowColor=color(h,s,b,60);
ellipse(0,0,2*R,2*R);
drawingContext.shadowBlur=0;
for(let i=0; i<ParticleSystem.length;i++){
ParticleSystem[i].update();
ParticleSystem[i].draw();
if(ParticleSystem[i].isDead()){ParticleSystem.splice(i,1);}
}
if(random(0,1)<0.5){
//let x = random(-R,R);
//let y = random(-sqrt(R*R-x*x),sqrt(R*R-x*x));
ParticleSystem.push(new Particle(0,0));}
}
class Particle{
constructor(x,y){
this.x=x;
this.y=y;
this.color = color(h+random(-30,30),s+random(-30,30),b+random(-10,10),100);
this.radius = random(2,4);
this.noiseScale = random(0.01,0.1);
this.speed = random(2,6);
this.theta = random(0,2*PI);
if (random(0,1)<0.5){this.speed=-this.speed;}
this.K1 = random(0,500);
}
update(){
this.theta += 0.2*(noise(this.K1*this.noiseScale)-0.5);
//this.theta += random(-0.1,0.1);
let dx1 = 0.2*this.speed*cos(this.theta);
let dy1 = 0.2*this.speed*sin(this.theta);
if(pow((this.x+dx1),2)+pow(this.y+dy1,2)<R*R){
this.x+=dx1;
this.y+=dy1;
}
else{
//this.x = - this.x;
//this.y= - this.y;
this.speed = -this.speed;
}
this.radius *= 0.999;
this.K1++;
}
isDead(){
if(this.radius<0.5){return true;}
else{return false;}
}
draw(){
noStroke();
fill(this.color);
ellipse(this.x,this.y,2*this.radius,2*this.radius);
}
}