class Particle { float x, y; float vx, vy; float friction; Particle(float _x, float _y) { x = _x; y = _y; vx = random(-1, 1) * 0.1; vy = random(-1, 1) * 0.1; friction = 0.98; } void wallCollision() { if (x < 0) { x = 0; vx *= -friction; } else if (x > width) { x = width; vx *= -friction; } if (y < 0) { y = 0; vy *= -friction; } else if (y > height) { y = height; vy *= -friction; } } void update() { vx *= friction; vy *= friction; x += vx; y += vy; } }