✨Effect Lab
Read the full guide完整技术长文 Text that moves: typing, per-character animation, and the terminal rain会动的文字:打字、逐字动画与终端数字雨
💠

Matrix Rain 矩阵数字雨

One rain column every 14px, each with its own falling head position — the tail is just an unfinished clearing. 每 14px 一列数字雨,每列有自己的下落头位置——尾巴其实是「没清干净的上一帧」。

Canvas 2DTrail fadeColumn state
Live demo实时演示

Runs live on this page. Move the pointer, click, or drag — whichever the effect listens for. 就在本页实时运行。移动鼠标、点击或拖拽——看它响应哪一种。

How it works原理拆解

Instead of clearRect, every frame paints rgba(0,0,0,0.08) over the canvas. That leaves 8% of the previous frame, which is what creates the fading tail. A column resets to 0 only when it is past the bottom AND Math.random() beats 0.975, so the columns desynchronise almost immediately. 它不用 clearRect,而是每帧盖一层 rgba(0,0,0,0.08)。上一帧留下 8%,就形成了拖尾。一列只有在下落到画布外、且 Math.random() 大于 0.975 时才归零,所以各列几乎立刻就不齐了。

What to change可以改的地方

  • 1Raise the clear alpha to 0.2 for short stubs, lower it to 0.03 for very long tails.
  • 2Widen the character set with katakana or binary and the code looks different at a glance.
  • 1清屏透明度改成 0.2 是短促的雨点,改成 0.03 是拖很长的尾巴。
  • 2换一套字符(片假名或纯 01),一眼看过去的风格就完全不同。

Source code源码

Self-contained — paste it into any HTML file and it runs. No libraries. 完全独立——粘进任意 HTML 文件就能跑,不需要任何库。

matrix.html