xxxxxxxxxx
let particles = [];
let numParticles = 300;
let noiseScale = 0.02;
function setup() {
createCanvas(800, 800);
background(10, 30, 10); // Colore scuro per effetto naturale
for (let i = 0; i < numParticles; i++) {
particles.push(new Particle(random(width), random(height)));
}
}
function draw() {
for (let p of particles) {
p.update();
p.show();
}
}
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = p5.Vector.random2D();
this.acc = createVector(0, 0);
this.maxSpeed = 2;
}
update() {
let angle = noise(this.pos.x * noiseScale, this.pos.y * noiseScale) * TWO_PI * 2;
let force = p5.Vector.fromAngle(angle);
this.acc.add(force);
this.vel.add(this.acc);
this.vel.limit(this.maxSpeed);
this.pos.add(this.vel);
this.acc.mult(0);
}
show() {
stroke(50, 255, 100, 80); // Colore verde naturale con trasparenza
strokeWeight(1.5);
point(this.pos.x, this.pos.y);
}
}