xxxxxxxxxx
54
//raiding insects
//Created by Mirette Dahab
//february 24th, 2025
//independant work
let particles = [];
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 150; i++) {
particles.push(new Particle(random(width), random(height)));
}
}
function draw() {
background(0, 120, 0, 50);
for (let p of particles) {
p.update();
p.display();
}
}
class Particle {
constructor(x, y) {
this.x = x;
this.y = y;
this.size = random(7, 10);
this.baseX = x;
this.baseY = y;
}
update() {
let d = dist(mouseX, mouseY, this.x, this.y);
let influence = map(d, 0, width, 2, 0.1); //influence factor based on distance from mouse
// Wave movement
let wave = sin(frameCount * 0.05 + this.baseX * 0.01 + this.baseY * 0.1) * 20;
this.x = this.baseX + wave * influence;
this.y = this.baseY + cos(frameCount * 0.05 + this.baseX * 0.1) * 20 * influence;
// Increase size if close to mouse
this.size = map(d, 0, 100, 7, 4);
}
display() {
let col = lerpColor(color(0, 0,0), color(255,255, 255), mouseX / width);
fill(col);
noStroke();
ellipse(this.x, this.y, this.size);
}
}