The Lab - Canvas

DVD screensaver

The bounce. The hue shift. The corner hit everyone waits for. On a canvas, in about 40 lines.

wall hits: 0 - corner hits: 0

How it works

The box has an (x, y) position and a (vx, vy) velocity; each frame adds velocity to position, and hitting a wall flips the matching component - two if statements are the whole physics engine. A hue rotation on impact gives the color cycling. The corner hit is just both flips on the same frame, and yes, the counter is honest.

Frames are driven by requestAnimationFrame with the step scaled by real elapsed time, so the pace is identical on a 60 Hz and a 144 Hz screen. The production version ships in rack.js on this site's homepage - idle long enough and it takes over the hero (its idle timeout is two minutes).