xxxxxxxxxx
55
let particles_a = [];
let particles_b = [];
let nums =50;
function setup(){
createCanvas(windowWidth, windowHeight);
background(21, 8, 50);
for(var i = 0; i < nums; i++){
particles_a[i] = new Particle(random(0, width),random(0,height));
particles_b[i] = new Particle(random(0, width),random(0,height));
}
}
function draw(){
noStroke();
for(let i = 0; i < nums; i++){
let radius = map(i,0,nums,1,3);
// fill(30, 81, 87);
particles_a[i].move();
particles_a[i].display(radius);
// fill(100, 91, 48);
particles_b[i].move();
particles_b[i].display(radius);
}
}
function Particle(x, y){
this.vel = p5.Vector.random2D();
this.pos = createVector(x, y);
this.color = color(random(255), random(255), random(255));
this.move = function(){
let mouse = createVector(mouseX, mouseY);
let angle = map(noise(10), 0, 1, 1, 50);
this.vel.mult(random(1));
this.acc = p5.Vector.sub(mouse, this.pos);
this.acc.setMag(cos(angle));
this.vel.add(this.acc);
this.pos.add(this.vel);
}
this.display = function(r){
fill(this.color);
ellipse(this.pos.x, this.pos.y, r, r);
}
}