Interactive Canvas Confetti Explosion JS
Click and 40 confetti pieces fire out from the cursor, arc over, then fall away and fade. There is no library involved, just a canvas and a requestAnimationFrame loop.
Each piece gets a random angle and speed, converted into velocity with cos and sin. That gives an even burst in every direction, unlike randomizing the x and y velocities separately, which quietly biases the spray toward the corners. Every frame multiplies velocity by a friction value and adds gravity to the vertical component.
Spin is drawn by translating the canvas to the particle position, rotating, then filling a rectangle around that origin. Faded particles are shifted off the front of the array, which is safe because they were pushed in age order. The loop keeps running when nothing is on screen, so cancel it with cancelAnimationFrame if battery life matters.