xxxxxxxxxx
let particles = [];
let numParticles = 100;
let letters = 'abcdefghijklmnopqrstuvwxyz'; // Array of characters
function setup() {
createCanvas(windowWidth, windowHeight);
// Create initial particles
for (let i = 0; i < numParticles; i++) {
particles.push(new Particle(width -width*1/10, height-height*1/10));
}
}
function draw() {
background(0, 100);
// Move and display particles
for (let i = particles.length - 1; i >= 0; i--) {
particles[i].update();
particles[i].display();
// Remove particles that are off-screen
if (particles[i].offScreen() ) {
particles.splice(i, 1);
particles.push(new Particle(width -width*1/10, height-height*1/10)); // Add new particle to replace the removed one
}
}
//console.log(particles.length);
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}
class Particle {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = createVector(-2, -2);
this.acc = createVector(0, 0);
this.maxSpeed = 3;
this.maxForce = 0.1;
this.noiseOffset = random(1000);
this.letter = letters.charAt(floor(random(letters.length))); // Choose a random letter from the array
}
update() {
// Apply noise to movement
let noiseX = map(noise(this.noiseOffset), 0, 1, -1, 1);
let noiseY = map(noise(this.noiseOffset + 1000), 0, 1, -1, 1);
let noiseVector = createVector(noiseX, noiseY);
noiseVector.mult(0.5);
this.acc.add(noiseVector);
this.acc.limit(this.maxForce);
this.vel.add(this.acc);
this.vel.limit(this.maxSpeed);
this.pos.add(this.vel);
this.acc.mult(0);
this.noiseOffset += 0.01;
}
display() {
fill(255);
textSize(28);
textAlign(CENTER, CENTER);
text(this.letter, this.pos.x, this.pos.y);
}
offScreen() {
return (this.pos.x < -20 || this.pos.y < -20 || this.pos.x > width + 20 || this.pos.y > height + 20);
}
}