21
\$\begingroup\$

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

Scoreboard:

┌-----┬------------┬------------┬-------------┬---------------┬--------------┐
| 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.

\$\endgroup\$

closed as off-topic by Dennis May 31 '16 at 18:37

  • This question does not appear to be about programming puzzles or code golf within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ What about libraries? \$\endgroup\$ – Vereos Jan 3 '14 at 10:31
  • \$\begingroup\$ Include or Import or Require as much libraries as you need(standard libraries)! \$\endgroup\$ – Renae Lider Jan 3 '14 at 10:41
  • \$\begingroup\$ 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) \$\endgroup\$ – ThinkChaos Jan 3 '14 at 14:10
  • \$\begingroup\$ 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) \$\endgroup\$ – Renae Lider Jan 3 '14 at 14:58
  • \$\begingroup\$ Alright, I'll include a golfed version just for fun! \$\endgroup\$ – ThinkChaos Jan 3 '14 at 15:04
17
\$\begingroup\$

HTML, Javascript and CSS: 1024 bytes, 47 points

Matrix rain demo

Features:

  • 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 :-)

Demo:

http://ruletheweb.co.uk/matrix.html

Source code:

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

<head><style>*{margin:0;padding:0;line-height:1;overflow:hidden;}div{width:1em;position:absolute;}</style><script>
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);x.style.opacity=0;r.appendChild(x)}r.id="r"+i;r.t=z(-99,0);with(r.style){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((e.style.opacity=1-v/32)==0){for(f in c)if(c[f].style)c[f].style.opacity=0;with(e.style){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()>
\$\endgroup\$
  • 2
    \$\begingroup\$ It looks good as a screen shot but it eats the crap out of my resources. +1 from me \$\endgroup\$ – Samuel Cook Jan 4 '14 at 2:25
  • \$\begingroup\$ Really cool! I might steal your unicode characters :) +1 \$\endgroup\$ – ThinkChaos Jan 4 '14 at 10:16
  • 1
    \$\begingroup\$ 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). \$\endgroup\$ – Konrad Borowski Jan 4 '14 at 15:43
  • \$\begingroup\$ 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 \$\endgroup\$ – RustyToms Feb 23 '17 at 19:21
10
\$\begingroup\$

Bash

1024 bytes (including comments)

COL=80
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
  done
}

# 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] &
done

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!

Edit: 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!

\$\endgroup\$
  • \$\begingroup\$ the golfed one is a bit of a fork-bomb, too ;) \$\endgroup\$ – Rob Starling Jan 3 '14 at 19:25
  • 1
    \$\begingroup\$ @RobStarling they both are actually! \$\endgroup\$ – ThinkChaos Jan 3 '14 at 19:58
  • 1
    \$\begingroup\$ 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 \$\endgroup\$ – Dom Hastings Jan 3 '14 at 20:08
  • \$\begingroup\$ Hmm. I'm getting 1059 bytes for first one and 190 bytes for the second. \$\endgroup\$ – Renae Lider Jan 3 '14 at 20:16
  • 1
    \$\begingroup\$ You guys are basically wizards! Thanks for sharing! \$\endgroup\$ – Dom Hastings Jan 4 '14 at 9:42
8
\$\begingroup\$

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

window.onload=function(){
    var tbl=document.createElement('table'),
	body=document.body;
	body.style.backgroundColor='#000';
	body.style.color='#060';
	body.style.fontFamily='Lucida Console';

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

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

\$\endgroup\$
6
\$\begingroup\$

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)
NEXT
s = TIMER

CLS
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
    NEXT

    l = TIMER
    WHILE l = TIMER
    WEND
WEND

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);
END SUB

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)
NEXT
s = TIMER
f = 0
w$ = "bullet"
o = 1
CLS
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
    NEXT
    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
        ELSE
            o = 1
        END IF

    END IF
    x = x + z
    l = TIMER
    WHILE l = TIMER
    WEND

WEND

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);
END SUB

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:

http://www.youtube.com/watch?v=MQc-FDl_AZ8

\$\endgroup\$
5
\$\begingroup\$

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&:&]

Effects

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
\$\endgroup\$
  • \$\begingroup\$ works perfectly on my TI-92! Awesome. \$\endgroup\$ – Renae Lider Jan 3 '14 at 21:49
  • \$\begingroup\$ @user3058846 I'm glad you like it :) I wasn't aware that GTB could execute on TI-92's though. \$\endgroup\$ – Timtech Jan 3 '14 at 21:52
  • \$\begingroup\$ TI-92 Plus actually. \$\endgroup\$ – Renae Lider Jan 3 '14 at 21:56
  • \$\begingroup\$ @user3058846 So you downloaded the compiler eh? Nice work :) \$\endgroup\$ – Timtech Jan 3 '14 at 21:58
4
\$\begingroup\$

Ruby: 374 characters

$><<"^[[2J"
w=->c,d,m{$><<"^[[0;3%d;%dm^[[%d;%dH%s"%[c,d[4],d[3]+d[1]-m,d[2],d[0][d[1]-m]]}
t=%w{Stack Exchange Programming Puzzle Code Golf}
r=[]
loop{r.map{|o|w[2,o,1]if o[1]>0
w[7,o,0]
o[1]+=1
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.)

Description:

  • 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

\$\endgroup\$
  • \$\begingroup\$ How many bytes (not characters)? \$\endgroup\$ – Renae Lider Jan 4 '14 at 16:10
  • 1
    \$\begingroup\$ Only single byte characters used, so 374 bytes. \$\endgroup\$ – manatwork Jan 4 '14 at 16:12
  • \$\begingroup\$ Really liked your version! Keep up the good work. \$\endgroup\$ – Renae Lider Jan 4 '14 at 17:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.