How the matrix rain effect works
Under the glow, the matrix rain effect is simple bookkeeping on a grid of character cells. Each column holds one or more drops, and a drop is only four numbers: a speed, a tail length, a start offset and a gap. Many browser versions fake the fading tail by painting a translucent black rectangle over the canvas every frame, so old characters dim on their own. Working out the brightness of every cell directly, as this piece does, takes a little more code but gives exact control over the fade and identical frames for the same moment, which matters when you export a GIF or a video.
Nothing needs to be stored between frames, because each one is worked out again from the clock. To rebuild it yourself:
- Lay out a grid in a monospace font so every cell holds exactly one character.
- Give every column a drop with a random speed, tail length, start offset and gap, so neighboring columns never fall in step.
- Each frame, find the head row as time multiplied by speed plus the offset, wrapped around the screen height plus the tail length plus the gap. That wrap is what makes a drop slide off the bottom, pause, and enter again at the top.
- Draw the head in white, then walk up the tail and step the green down from bright to dark as the distance from the head grows.
- Swap characters on a schedule: quickly at the head, slowly along the tail. Picking each glyph from a hash of column, row and time step keeps the flicker steady instead of noisy.
- Optionally fill the empty cells with a faint layer of dark green code so the screen never looks blank between streams.
