xxxxxxxxxx
40
"use strict";
var particles = [];
let accelerationFactor = 0.1; // Acceleration multiplier for controlling speed
let repulsionRadius = 100; // Radius around the mouse for repulsion
function setup() {
createCanvas(600, 600);
noStroke();
}
function draw() {
background(0);
// Add particles periodically
if (frameCount % 2 == 0) {
particles.push(new Particle(random(10, 45), random(30, 45)));
particles.push(new Particle(random(195, 220), random(195, 220)));
}
for (var i = particles.length - 1; i > 0; i--) {
var p = particles[i];
p.update();
p.repulse(); // Apply repulsion force if near the mouse
p.display();
// Remove particle if outside bounds or faded out
if (p.isOutside() || p.a <= -10) {
particles.splice(i, 1);
}
}
// Control the acceleration factor dynamically with arrow keys
if (keyIsDown(UP_ARROW)) {
accelerationFactor += 0.01; // Increase acceleration with up arrow
}
if (keyIsDown(DOWN_ARROW)) {
accelerationFactor = max(0, accelerationFactor - 0.01); // Decrease with down arrow
}
}