Matrix rain: animated falling green code in ASCII

Columns of green glyphs falling at different speeds, each led by a bright white head.

Demoscene84×3024 fps2.0 KB
Look

Use it Docs

Paste two lines into any page, use it from React, play it in a terminal, put a GIF in a README, or hand the Agent prompt to your coding agent. Every tab follows the look you pick above.

<script type="module" src="https://www.ascii-magic.com/ascii/ascii.js"></script>

<ascii-art piece="matrix-rain"></ascii-art>

Export

Pause on the frame you like, pick a look, then download it at an exact size.

Share

← Mars ColonyMaze Builder →

Digital Rain is a ready-made matrix rain animation: columns of green glyphs falling at different speeds, each stream led by a bright white head and trailing a tail that fades into the dark. It is drawn entirely in text characters at 24 frames per second, weighs only a few KB, and works as a hacker background, a terminal show, a GIF or a wallpaper.

The falling code animation is a classic of hacker-style screens and terminals, and people usually want one of two things from it. If you just want the look, embed it with one tag, play it in a terminal, or export a GIF, a video or a 4K wallpaper. If you would rather build your own, the sections below explain how the matrix rain effect works and exactly how this version is drawn.

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.

What this digital rain shows and how it is drawn

Digital Rain fills an 84 by 30 character grid and redraws it 24 times a second. Every column carries two drops, so 168 streams are in play at once and a column sometimes shows two trails at different heights. Each drop has its own pace, from 6 to 20 rows a second, so a fast stream crosses the screen in about a second and a half while a slow one takes five seconds. Tails run from 10 to 29 characters, and once a drop clears the bottom it waits for a gap of up to 23 rows before it re-enters at the top.

Color does most of the work. The head of each stream is a near-white mint, the characters just behind it are bright green, and the tail steps down a ramp of greens toward a deep forest shade. Behind the streams, every cell holds a dim character in very dark green, and that whole background field reshuffles twice a second. Heads change glyph 14 times a second while tail glyphs change three times a second, so the leading edge shimmers and the trail settles.

The 50 glyphs are the 26 capital letters, the digits 0, 1, 3, 5, 7 and 9, and code symbols such as brackets, braces, slashes, pipes, colons and the operators = + * < >. Sticking to these keeps the effect readable in any monospace font. The drops come from a seeded random generator, so the rain falls in the same pattern every time it loads. The full MIT licensed source, about 50 lines, sits under Source on this page.

How to use this matrix rain: web, React, terminal and exports

The code tabs and export buttons on this page cover the common jobs, so pick the one that matches where the rain needs to go:

  • Web page: add the script tag once, then <ascii-art piece="matrix-rain"></ascii-art> wherever the rain should appear. For a hero, place it behind your headline. For a full-page hacker background, pin it behind your content with CSS. Use bg for the base color, size for the character size and speed="0.5" to calm it so text on top stays readable. For a step by step hero, see An animated ASCII hero for GitHub Pages.
  • React: copy matrix-rain.js and kit.js into your project and use the component from the React tab, which runs the piece and writes each frame into a pre element. It writes plain text, so color it with CSS, or use the ascii-art tag inside your JSX to keep the full green ramp.
  • Terminal: the Terminal tab holds a one-line command that plays the rain in color. Add --seconds=3 so it stops on its own, or --frame to print a single still frame.
  • README: download the GIF, commit it to your repository and paste the README tab's snippet, which centers the image at 720 pixels wide.
  • Video: export MP4 or WebM at 1920x1080, or 4K, for a video intro, a title background or a screen at an event.
  • Wallpapers and social sizes: pause on a dense frame, then export a PNG for desktop in 4K or 1080p, a phone, a 1280x720 video thumbnail, a GitHub social preview, a square post or a story.
  • Looks: switch to Binary for pure ones and zeros, try Numbers or Letters for a different texture, Halftone dots for a print feel, or type your own characters, such as the letters of your product name. Copy as text grabs the current frame as plain text for a code comment or a chat message.

Where a matrix code rain background fits

Falling code says technical before anyone reads a word, which makes it a dependable backdrop for developer work and anything with a hacker theme:

  • Developer portfolios: run it slowly behind your name, or keep it in a corner card beside Code Editor, so the page feels like a working machine without shouting.
  • Hacker-themed landing pages: a dark hero with the rain at low speed suits security tools, coding events, capture the flag contests and puzzle hunts.
  • Stream overlays and starting soon screens: load it as a browser source behind a countdown or a break message. See Animated ASCII overlays for OBS and streams for the setup.
  • Terminal welcome: play a few seconds of rain when a shell opens, or print one still frame as a login banner. See A terminal welcome screen with animated ASCII art.
  • Wallpapers: a green code rain wallpaper in 4K for the desktop, a phone size for the lock screen, or a frame behind a video title. See ASCII art wallpapers for desktop and phone.
  • Pairings: Neon City Rain swaps code for a wet neon street at night, TV Static and CRT Test Card from Demoscene add a broken signal, and Boot Sequence and Terminal Session build a convincing machine room around the rain.
  • More like it: for other screens in the same spirit, browse the UI and Retro Computing categories, or explore the whole ASCII library.

/FAQS

Matrix rain: frequently asked questions

Q. What is matrix rain?
Matrix rain is an animation of green characters falling down a dark screen in vertical streams, like code pouring down a monitor. Each stream has a bright leading character and a tail that fades out behind it. It is also called digital rain or falling code, and it is a classic of hacker-style screens, screensavers and terminals.
Q. How do I code a matrix rain effect in JavaScript?
Give each column of a character grid a drop with its own speed, tail length and start offset, then redraw every frame from the clock. Draw the head in white, fade the tail through darker greens, and swap glyphs faster at the head than along the tail. The MIT licensed source of this piece, under Source on this page, does it in about 50 lines.
Q. Can I use matrix rain as a website background?
Yes, add the script tag and <ascii-art piece="matrix-rain"></ascii-art>, then position it behind your content with CSS. Set bg for the base color and a lower speed so text on top stays readable. It draws to a canvas, plays only while it is on screen, and shows a still frame to visitors who prefer reduced motion.
Q. How do I play digital rain in my terminal?
Run npx --yes ascii-magic-art matrix-rain and the rain plays in color in your terminal. Add --seconds=3 so it stops on its own, which suits a shell startup, --frame to print one still frame, or --look=binary for ones and zeros. Press any key or Ctrl+C to stop it early.
Q. How do I get a green code rain wallpaper?
Pause the player on a frame you like and export a PNG wallpaper in Desktop 4K, 1080p or phone size. The frame is drawn fresh at the size you pick, so the characters stay sharp instead of being stretched from a small image. For a moving desktop, export an MP4 or WebM video and set it with any app that plays video wallpapers.
Q. Can I add a falling code animation to my GitHub README?
Yes, download the GIF from this page, commit it to your repository, and paste the snippet from the README tab. The snippet centers the image and shows it 720 pixels wide, which suits a profile or a project page. Pick a smaller export size and keep the clip short so the file stays light and loads quickly.
Q. Can I download the matrix code rain as a video?
Yes, export it as MP4 or WebM at 1920x1080 by default, with a 4K option for large screens. Use the clip as a background plate in a video edit, an intro behind a title, or a display screen at an event or a meetup. The clip starts from the moment showing in the player, so pause where you want it to begin.
Q. How do I use a hacker background on a live stream?
Load the piece as a browser source in your streaming software, then layer your camera, countdown or chat on top of it. Slow the speed for a calmer starting soon screen or a break scene, and set bg to match your overlay. See Animated ASCII overlays for OBS and streams for the setup step by step.
Q. Can I change the characters in the falling code?
Yes, switch the look to Binary for ones and zeros, to Numbers, Letters or Blocks for other textures, or type your own characters. On a web page, set look="binary" or pass your own set with chars, ordered from light to dark. The streams and their speeds stay the same, and only the characters change.
Q. How do I add digital rain to a React app?
Use the ascii-art tag inside your JSX after loading the script, or copy the component from the React tab. The component imports matrix-rain.js and kit.js from your project and writes each frame into a pre element on every animation frame. It outputs plain text, so give the pre a green color and a dark background with CSS.
Q. Will an animated code rain background slow down my site?
It should not, since the piece is only a few KB and paints onto a single canvas. Animation stops whenever the rain scrolls out of view and resumes when it returns, and people who ask for reduced motion see one still frame instead. Running it at a lower speed behind text also makes the page easier on the eyes.
Q. Can I use this digital rain animation in a commercial project?
Yes, Digital Rain is MIT licensed, so you can use it in personal and commercial work, including client sites, products, videos and streams. Credit is appreciated but not required. The license covers the source code too, so you can change the colors, speeds or glyph set to fit your own design.

Source GitHub

MIT licensed and open source on GitHub. It imports one small helper file, kit.js. This is the animation itself: what gets drawn in every frame. The look you pick is applied on top by the player, like a filter, so this file stays the same in every look while the snippets above change with it. Edit it to change the animation; see the docs to make your own.

/* matrix-rain: columns of green glyphs falling like digital rain. */
import { Grid, palette, gradient, KEYS, rng } from "../lib/kit.js";

const GREEN = gradient(["#021a08", "#04390f", "#0a6b1d", "#13a82c", "#2fe05a", "#9dffb0"], 14);

export const meta = {
  slug: "matrix-rain",
  name: "Digital Rain",
  category: "demoscene",
  note: "Columns of green glyphs falling at different speeds, each led by a bright white head.",
  tags: ["code", "rain", "hacker", "terminal", "hero", "wallpaper"],
  cols: 84, rows: 30, fps: 24,
  palette: palette([...GREEN, "#f2fff4"]),
};

const GLYPHS = "01ZXCVBNMASDFGHJKLQWERTYUIOP<>=+*:;|/\\[]{}#$%&7395";

export default function create() {
  const { cols, rows } = meta;
  const g = new Grid(cols, rows);
  const r = rng(42);
  const drops = [];
  for (let x = 0; x < cols; x++) for (let k = 0; k < 2; k++) {
    drops.push({ x, speed: 6 + r() * 14, len: 10 + Math.floor(r() * 20), off: r() * 200, gap: Math.floor(r() * 24) });
  }
  const glyph = (x, y, s) => {
    let h = (x * 374761393 + y * 668265263 + s * 1442695041) | 0;
    h = Math.imul(h ^ (h >>> 13), 1274126177);
    return GLYPHS[((h ^ (h >>> 16)) >>> 0) % GLYPHS.length];
  };
  return (t) => {
    g.clear();
    // dim background code everywhere, changing slowly
    const slow = Math.floor(t * 2);
    for (let y = 0; y < rows; y++) for (let x = 0; x < cols; x++) g.set(x, y, glyph(x, y, slow + ((x * 7) % 5)), KEYS[(x * 3 + y) % 4 === 0 ? 2 : 1]);
    for (const d of drops) {
      const span = rows + d.len + d.gap;
      const head = ((t * d.speed + d.off) % span);
      const hy = Math.floor(head);
      for (let i = 0; i < d.len; i++) {
        const y = hy - i;
        if (y < 0 || y >= rows) continue;
        const f = 1 - i / d.len;
        const s = Math.floor(t * (i === 0 ? 14 : 3)) + i;
        if (i === 0) g.set(d.x, y, glyph(d.x, y, s), "e");
        else g.set(d.x, y, glyph(d.x, y, s), KEYS[Math.max(2, Math.min(13, Math.floor(f * 13)))]);
      }
    }
    return g.frame();
  };
}

More demoscene

Classic demo effects: fire, plasma, tunnels and warps.

/YOUR OWN

Turn your own image or video into ASCII

The pieces here are hand-built animations. To turn your own photo, logo or video into animated ASCII, use the ASCII Magic editor.