Make the Matrix Digital Rain using the shortest amount of code

  • Rules:

    • Any language you choose (Standard Libraries).

    • Output displayed in Terminal or Windows Command Processor or any other way you prefer.
      (width buffer = 80)

    • ASCII Characters are enough. (may add Unicode)

    • Shouldn't fill up the entire screen at start-up (Should look like a rain, duh!).

    • Colors gets bonus points (+5).

    • Effects : Random characters, different fall sizes, regenerates periodically.

    Points: (update)

    • +32 points to start with.

    • -1 point for every byte (not chars) in the code after the **1024***th* byte.

    • Points could reach zero and negative.

    • Note: Languages using multibyte characters should count bytes not characters.

    • +5 for every new effect. (not posted by others)

    • +15 for any of these effects:

      1. Wind(blows characters to the side)

      2. Number Matching(user input, eg:90210):

        Number is randomly located within the matrix

        enter image description here

      3. Sound

      4. Encrypted msg(user input):

        Characters represent a secret encrypted message

      5. Galaga mode:

        Fires ^ to destroy characters

        enter image description here


    | pos | name | type | bytes | effects | points ^ |
    |1 |nitro2k01 |QBasic |913 |Colours |+57 |
    | | | | |Colour Fade | |
    | | | | |Sound (+15) | |
    |2 |squeamish |HTML, Java- |1024 |Colours |+47 |
    | |ossifrage |Script, CSS | |Transition | |
    | | | | |Size Variation | |
    |3 |manatwork |Ruby |374 |Colours |+47 |
    | | | | |Actual Words | |
    | | | | |Character - | |
    | | | | | Disperse | |
    |4 |plg |Bash |1024 |Colours |+42 |
    | | | | |Random Pause | |
    |5 |Timtech |TI-84 calc |120 |Umbrella |+42 |
    | | | | |Run Inside | |
    |6 |Samuel Cook |JavaScript |830 |Colours |+42 |
    | | | | |Transition | |

    Note : Scoreboard will/could be updated by anyone after posting a valid answer. Do not exceed top ten positions. Add more effects to your code and beat your own score!
    Clearing initial screen, cleanup, bugs, third party libraries etc. would not count towards the points
    Remember to include details about no. of bytes used and the name of language or program.

    Neo: What are you trying to tell me? That I can dodge bullets?

    Morpheus: No, Neo. I'm trying to tell you that when you're ready, you
    won't have to.

    What about libraries?

    Include or Import or Require as much libraries as you need(standard libraries)!

    Would you add points if the code is under 250 chars? (I have a really short solution but it doesn't have a ton of features)

    You won't be needing it; you'd still have +32 points! Chances are, many will exceed the limit and begin to drop points making short codes raise to top on the scoreboard. *(also, adding more rules and points would complicate stuff)*

    Alright, I'll include a golfed version just for fun!

    Shell script: 7 characters – `cmatrix`

    I was wondering if anyone could pull off these effects: **1. Wind(blows characters to the side), 2.Number Matching(user input), 3.Sound, 4.Encrypted msg(user input), 5.Galaga mode**

    @user3058846 Can you clarify what number matching, encrypted message and Galaga mode mean exactly?

    @nitro2k01 Edited the question, check it out.

    I'm surprised that no one has tried Python yet!

    although not in competition, check this :

    Questions without an objective validity criterion are off-topic, as they make it impossible to indisputably decide whether an entry complies with the specification. *Looks like rain* and *new effect* are subjective.

  • HTML, Javascript and CSS: 1024 bytes, 47 points

    Matrix rain demo


    • Uses Unicode characters (don't think this scores any points though)

    • Trails fade from bright to dark green while they are being drawn (*)

    • Trails also fade from dark green to black after the drawing has finished (*)

    • Random text size in each trail (*)

    • Trails are randomly repositioned and resized each time they are drawn

    (*) I'll claim +5 points for each of these, but let me know if you disagree :-)


    Source code:

    Exactly 1024 bytes. It's a bit ugly, I'm afraid.

    w=window;n=w.innerWidth;m=w.innerHeight;d=document;q="px";function z(a,b){return Math.floor(Math.random()*(b-a)+a)}f=" 0123456789";for(i=0;i<45;i++)f+=String.fromCharCode(i+65393);function g(){for(i=0;i<90;i++){r=d.createElement("div");for(j=z(20,50);j;j--){x=d.createElement("pre");y=d.createTextNode(f[z(0,56)]);x.appendChild(y);;r.appendChild(x)}"r"+i;r.t=z(-99,0);with({left=z(0,n)+q;top=z(-m,0)+q;fontSize=z(10,25)+q}d.body.appendChild(r);setInterval("u("+i+")",z(60,120))}}function u(j){e=d.getElementById("r"+j);c=e.childNodes;t=e.t+1;if((v=t-c.length-50)>0){if(({for(f in c)if(c[f].style)c[f].style.opacity=0;with({left=z(0,n)+q;top=z(-m/2,m/2)+q;opacity=1}t=-50}}e.t=t;if(t<0||t>c.length+12)return;for(f=t;f&&f>t-12;f--){s=1-(t-f)/16;if(f<c.length&&c[f].style){c[f].style.opacity=s;}}}
    </script><body text=#0f0 bgcolor=#000 onload=g()>

    It looks good as a screen shot but it eats the crap out of my resources. +1 from me

    Really cool! I might steal your unicode characters :) +1

    UglifyJS can remove 17 characters from JavaScript source code. Not that it really matters, as this is not code golf (rather, max 1024 characters challenge).

    This is by far the best version of this I have found on the first two pages of Google results. I just really wish you had had some room to actually remove some of the nodes you are adding :) really kills my computer to leave that open

    Do you by chance have the original pre-uglified code? I would love to understand how this is done.

    That's great, thanks! I don't quite understand the part around the opacity being result of some function of the age divided by 16 and 32 - are those numbers arbitrary or is there a special meaning to them? Also another interesting thing I noticed is this consumes much less system resource on Firefox instead of Chrome, not sure why, but Chrome seems to max out my GPU.

    @Chin The opacity variation was just added to make the characters fade after a while. If you fiddle around with the numbers, you should be able to see what's happening. And yes, it is quite demanding on the processor.

  • Bash

    1024 bytes (including comments)

    ROW=$(tput lines)

    cleanup() {
    wait # wait for background jobs (the drops)
    # clear; move cursor to (1,1); show cursor
    # reset color
    printf '\033[2J\033[1;1H\033[?25h\033[0;0m'

    drop() { # $1=column ; $2=row to end on ; $3 = drop size (ranges from 5 to 15)
    for ((r=1; r<$2+$3+1; r++)); do
    # if before drop's end point : print lowest char in white
    [ $r -lt $2 ] && printf "\033[$r;$1H\033[0;0m\u$[RANDOM % 59 + 21]"

    # if before or on drop's end point : replace older white char with a green one
    [ $r -le $2 ] && printf "\033[$[r-1];$1H\033[0;32m\u$[RANDOM % 59 + 21]"

    # if drop's longer than it's size : erase last char
    [ $r -gt $3 ] && printf "\033[$[r-$3];$1H "

    # wait before moving drop down
    sleep .1

    # cleanup on exit
    trap cleanup EXIT
    # clear screen; hide cursor
    printf '\033[2J\033[?25l'

    # loop with delay
    while sleep .1; do
    # start a drop in background : column; ending row; size
    drop $[RANDOM % COL] $[RANDOM % ROW + ROW/3] $[RANDOM % 10 + 5] &

    New effects:

    • everything (first entry) ;)

    • drops will stop randomly on the screen

    • cool color effects: the last char is white while the others are green

    • random chars and escape sequences stay on the console... Ok, that's a bug but it's because the term can't keep up with the cursor movement

    Golfed @ 188 186 176 :

    d(){ for((r=1;r<$2+41;r++));do $4"$3$r;$1H\u$[RANDOM%59+21]";(($r>$2))&&$4"$3$[r-$2];$1H ";$s;done;}
    s=sleep\ .1;while $s;do d $[RANDOM%80] $[RANDOM%10+5] '\033[' printf\ &done

    This works in a 80x40 grid. You can change that in RANDOM%80 on the last line, and r<$2+41 on the 2nd one. I don't clear the drops after they get out of the grid so either resize your term to 80x40 or change 41 to $LINES+1.
    There are a couple things it doesn't have compared to the full version :

    • term preparation or cleanup

    • fancy coloring (takes 52 bytes, so not worth it)

    • stopping randomly (here drops always go down to the bottom)

    • I could bring it down to 174 by not specifying a minimum length for "drops" : $[RANDOM%10+5] would become $[RANDOM%15]

    Even with those limitations I think it's pretty cool!

    I tried using unicode chars like squeamish ossifrage, but because they're double width chars they fill the grid pretty rapidly and it ends up looking strange.

    I also reduced the golfed version by using unicode code points instead of ASCII, so I don't have to go octal before getting a character, saving a step. I did the same thing in the main version, but added comments to keep it at 1024 bytes.

    And then changed int comparison from [ $r -gt $2 ] to (($r>$2)), that white space was killing me but I couldn't find another method that compared ints and not strings. This got the golfed version down to 176 btyes!

    the golfed one is a bit of a fork-bomb, too ;)

    @RobStarling they both are actually!

    Really loving this! I've tinkered with it a little and it seems you could make it green by changing `\033[` to `\033[0;32m\033[` (at least in my terminal). How bad an idea is it to try and set this up as a terminal screensaver? :P

    Hmm. I'm getting 1059 bytes for first one and 190 bytes for the second.

    @DomHastings Yeah, the full version does coloring, I just didn't want to add extra bytes to the golf one, especially because having nice coloring (ie. not ALL green) requires 52 bytes. If you think this is cool check this out. I found that after I wrote mine, and he has stuff like Mandelbrot fractal, fire animation nyan cat, he's great!

    @user3058846 Your text editor uses `\r\n` as line endings, I used the plain `\n`. My reasoning behind this : first script is 36 lines, you added `\r` to each line ending so you added 35 bytes (if there's no trailing newline). Lo and behold `1024 + 35 = 1059`. Same thing for script 2: `188 + 2 = 190`

    Fixed the EOL Characters (Windows defaults to \r\n, but I think Unix systems use \n)

    Tried it, that's awesome! you're good.

    You guys are basically wizards! Thanks for sharing!

  • JavaScript, 830 bytes

    It has all of the classic features like:

    1. black background

    2. green text

    3. white text when falling

    4. random characters

    5. empty holes

    6. infinite looping

    var tbl=document.createElement('table'),
    body=document.body;'#000';'#060';'Lucida Console';

    for(var i = 0; i <= 30; i++){
    var tr = tbl.insertRow();
    for(var j = 0; j <= 50; j++){
    var td = tr.insertCell();"2%";
    function rain(n,i) {
    setTimeout(function (){
    var e=document.getElementsByTagName('tr')[i].childNodes[n];'#fff';
    e.innerHTML = '&#'+Math.floor((Math.random()*127)+1)+';';

    if (i++ < 30) rain(n,i);

    I like it because it is incredibly light weight, fluid in motion, and simple. enjoy!

  • QBasic 1, 587 bytes, 32+5=37 points

    DECLARE SUB d (p!, s!, x!, y!)
    DIM t(80)
    FOR i = 1 TO 80
    t(i) = INT(-50 * RND)
    s = TIMER

    WHILE 1
    FOR i = 1 TO 80
    IF t(i) > 28 THEN t(i) = 0
    t(i) = t(i) + 1
    y = t(i)
    d 0, 0, i, y - 6
    d 2, 0, i, y - 5
    d 2, 0, i, y - 4
    d 10, 0, i, y - 3
    d 10, 0, i, y - 2
    d 11, 0, i, y - 1
    d 0, 2, i, y

    l = TIMER

    SUB d (p, s, x, y)
    COLOR p, s
    IF y > 0 AND y < 24 THEN LOCATE y, x: PRINT CHR$(33 + (x * y) MOD 200);

    Sample screenshot:

    QBasic matrix 1

    32 base points + 5 points for color. But since I'm floating happily well below 1024 byte even without whitespace trimming or optimization, let's add a few more things to steal some points:

    QBasic 2, 913 bytes, 32+5+15+5=57 points

    DECLARE SUB d (p!, s!, x!, y!)
    DIM t(80)
    FOR i = 1 TO 80
    t(i) = INT(-50 * RND)
    s = TIMER
    f = 0
    w$ = "bullet"
    o = 1
    WHILE 1
    FOR i = 1 TO 80
    IF t(i) > 28 THEN t(i) = 0: IF f THEN SOUND 100 * i, 1
    t(i) = t(i) + 1
    y = t(i)
    d 0, 0, i, y - 6
    d 2 + x, 0, i, y - 5
    d 2 + x, 0, i, y - 4
    d 10 + x, 0, i, y - 3
    d 10 + x, 0, i, y - 2
    d 11 + x, 0, i, y - 1
    d 0, 2 + x, i, y
    k$ = INKEY$
    IF k$ <> "" THEN
    IF MID$(w$, o, 1) = k$ THEN
    o = o + 1
    IF o = LEN(w$) + 1 THEN z = 1: f = 100
    o = 1
    END IF

    END IF
    x = x + z
    l = TIMER


    SUB d (p, s, x, y)
    COLOR p MOD 16, s MOD 16
    IF y > 0 AND y < 24 THEN LOCATE y, x: PRINT CHR$(33 + (x * y) MOD 200);

    Sample screenshot (color effect activated):

    Qbasic matrix 2

    Same features as the first one. Additionally it has:

    • Color (+5)

    • A password to activate extra features. (I'm claiming +5 for this as a new feature.)

    • The password activates a palette fade and sound effects. (+15 for sound.)

    Video showing it in action, including the color effect and sound effect activated by the password:

  • GTB, 42 points

    Executed from a TI-84 calculator, about 100 bytes:

    "  O O    O O   O"→Str1:"O  O   O O  O O "→Str2:0→X[@getkey=25$~""~""~""~""~""~""~""p;&@round(r;$~""#@round(r;$~Str1#~Str2&:&]


    Since the calculator is black + white to begin with, can't do much there...

    • Umbrella - Pressing the up key clears off the rain and keeps you dry until you press Enter

    • Run Inside - Pressing ON breaks the program and gives you a nice roof to keep you dry (you can go back out into the rain by pressing Enter twice

    works perfectly on my TI-92! Awesome.

    @user3058846 I'm glad you like it :) I wasn't aware that GTB could execute on TI-92's though.

    TI-92 Plus actually.

    @user3058846 So you downloaded the compiler eh? Nice work :)

  • Ruby: 374 characters

    t=%w{Stack Exchange Programming Puzzle Code Golf}
    loop{{|o|w[2,o,1]if o[1]>0
    o[0][0]==" "?r.delete(o):(o[0]=" "*o[1])*o[1]=0if o[1]>o[0].size}
    sleep 0.1
    r<<[(k=rand(10)%2)==0 ?t.sample: [*?a..?z].sample(rand(10)+5)*"",0,rand(80),rand(20),k+1]while r.size<25}

    (Note: ^[ are single characters.)


    • 25 simultaneous runs (kept low so the predefined texts remain readable)

    • each run has 50% / 50% chance to be either

      • a predefined word – displayed in bright colors

      • a random string of 5..15 lowercase letters – displayed in dark colors

    • while displaying the run the bottom color is white, the others green

    • after the run is fully displayed, it is removed character by character

    Sample run:

    matrix rain

    How many bytes (not characters)?

    Only single byte characters used, so 374 bytes.

    Really liked your version! Keep up the good work.

License under CC-BY-SA with attribution

Content dated before 7/24/2021 11:53 AM