xxxxxxxxxx
43
let particles = []; // variable for the particles
const num = 2000 // how many particles will be displayed
const noiseScale = 0.01;
function setup() {
createCanvas(800, 600);
for(let i = 0; i < num; i++) {
particles.push(createVector(random(width), random(height)));
}
}
function draw() {
background(0); // changed background to black
for(let i = 0; i < num; i++) {
let p = particles[i];
let n = noise(p.x * noiseScale, p.y * noiseScale);
// Change particle color
let particleColor = color(random(255), random(255), random(255), 150); // random color with transparency
fill(particleColor);
// Change particle speed
let speed = map(n, 0, 1, 0.5, 2); // adjust speed based on noise value
// Draw rectangle particles
let particleSize = map(n, 0, 1, 2, 20); // scale particle size based on noise value
rect(p.x, p.y, particleSize, particleSize); // draw rectangle with scaled size
// Update particle position
let a = TAU * n;
p.x += cos(a) * speed;
p.y += sin(a) * speed;
// Wrap particles around canvas edges
if (p.x < 0) p.x = width;
if (p.x > width) p.x = 0;
if (p.y < 0) p.y = height;
if (p.y > height) p.y = 0;
}
}