xxxxxxxxxx
let particles = [];
let noiseScale = 0.02;
let colors;
function setup() {
createCanvas(windowWidth, windowHeight);
colors = [
color(255, 0, 255, 100), // Magenta trasparente
color(0, 255, 255, 100), // Ciano trasparente
color(255, 255, 0, 100) // Giallo trasparente
];
for (let i = 0; i < 300; i++) {
particles.push(new Particle());
}
}
function draw() {
background(0, 20); // Sfondo con leggero fade per effetto persistente
for (let p of particles) {
p.update();
p.show();
}
}
class Particle {
constructor() {
this.pos = createVector(random(width), random(height));
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
this.maxSpeed = 3;
this.color = random(colors);
this.size = random(2, 5);
}
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); // Reset accelerazione
// Effetto warp ai bordi per fluidità infinita
if (this.pos.x > width) this.pos.x = 0;
if (this.pos.x < 0) this.pos.x = width;
if (this.pos.y > height) this.pos.y = 0;
if (this.pos.y < 0) this.pos.y = height;
}
show() {
noStroke();
fill(this.color);
ellipse(this.pos.x, this.pos.y, this.size);
}
}