Matrix digital rain: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 8:
=={{header|Ada}}==
Should work with ANSI terminals.
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO;
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Fixed;
Line 100:
Put (ESC & "[49m"); -- Default backgound
Put (ESC & "[2J"); -- Clear Terminal
end Digital_Rain;</langsyntaxhighlight>
 
=={{header|Batch File}}==
{{Works with|Windows 10}}
This code uses Windows 10 VT100 escape sequences.
<langsyntaxhighlight lang="dos">:: Matrix Digital Rain Task from RosettaCode
:: Batch File Implementation
 
Line 152:
<nul set /p "=%esc%[1T%esc%[1;1H" %== scroll down and set cursor position to home ==%
echo(%disp_line%
goto matrix_loop</langsyntaxhighlight>
 
=={{header|C}}==
Line 173:
 
And here's the code :
<syntaxhighlight lang="c">
<lang C>
/**
* Loosely emulates the "digital rain" effect from The Matrix.
Line 296:
return 0;
}
</syntaxhighlight>
</lang>
===Microsoft Windows console version===
====Single threaded====
{{Works with|Microsoft Visual Studio C}}
<langsyntaxhighlight Clang="c">/*******************************************************************************
*
* Digital ASCII rain - the single thread variant.
Line 484:
 
return 0;
}</langsyntaxhighlight>
 
====Multiple threads====
{{Works with|Microsoft Visual Studio C}}
<langsyntaxhighlight Clang="c">/*******************************************************************************
*
* Digital ASCII rain - multithreaded.
Line 691:
 
return 0;
}</langsyntaxhighlight>
 
====Fibers====
{{Works with|Microsoft Visual Studio C}}
<langsyntaxhighlight Clang="c">/*******************************************************************************
*
* Digital ASCII rain - multithreaded.
Line 890:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 898:
Runs in the terminal (using the Ncurses C library and the croatoan Lisp wrapper).
 
<langsyntaxhighlight lang="lisp">
(defun matrix-digital-rain ()
(with-screen (scr :input-echoing nil :input-blocking nil :cursor-visible nil)
Line 931:
(setf (frame-rate scr) 20)
(run-event-loop scr))))
</syntaxhighlight>
</lang>
 
{{out|Sample output}}
Line 941:
 
Rather than pressing Ctrl+C to stop the program, I've added code so that it stops automatically after 1 minute and restores the terminal to its original state.
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,046:
}
}
}</langsyntaxhighlight>
 
=={{header|J}}==
Line 1,053:
Some key issues are the (deliberate) relatively low resolution of the screen in the movie, a somewhat slow update rate and some variation over time in the update rate of the screen. This implementation is, of course, only an approximation...
 
<langsyntaxhighlight Jlang="j">require'ide/qt/gl2'
coinsert'jgl2'
 
Line 1,096:
pshow;
timer 100
}}</langsyntaxhighlight>
 
Notes:
Line 1,108:
=={{header|Javascript}}==
El código es de Christian Behler (christian@pingpoli.de)
<langsyntaxhighlight lang="javascript">var tileSize = 20;
// a higher fade factor will make the characters fade quicker
var fadeFactor = 0.05;
Line 1,239:
fadeFactor = Math.min(Math.max(document.getElementById("fadeFactor").value , 0.0) , 1.0);
initMatrix();
}</langsyntaxhighlight>
Html to test:
<pre><!DOCTYPE html>
Line 1,278:
=={{header|Julia}}==
The font used is based on Leonardo da Vinci's notebooks. The font is freely obtainable at https://www.wfonts.com/font/leonardos-mirrorwriting.
<langsyntaxhighlight Julialang="julia">using Gtk, Colors, Cairo
import Base.iterate, Base.IteratorSize, Base.IteratorEltype
 
Line 1,359:
 
digitalrain()
</syntaxhighlight>
</lang>
 
=={{header|Locomotive Basic}}==
 
<langsyntaxhighlight lang="locobasic">10 mode 0:defint a-z:randomize time:ink 0,0:ink 1,26:ink 2,19:border 0
20 dim p(20):mm=5:dim act(mm):for i=1 to mm:act(i)=rnd*19+1:next
30 md=mm-2:dim del(md):for i=1 to md:del(i)=rnd*19+1:next
Line 1,373:
90 p(x)=p(x)+1:if p(x)=25 then p(x)=0:del(i)=rnd*19+1
100 next
110 goto 40</langsyntaxhighlight>
The program above runs at an acceptable speed on a 4 MHz Z80, but can be made much faster by using the [https://benchmarko.github.io/CPCBasic/cpcbasic.html CPCBasic JavaScript emulator]. CPCBasic also adds an 80x50 display mode ("mode 3") which real CPC hardware lacks. Changing screen size from 20x25 to 80x50 and adding a delay with "frame" in line 100 results in a far more impressive display in CPCBasic:
<langsyntaxhighlight lang="locobasic">10 mode 3:defint a-z:randomize time:ink 0,0:ink 1,26:ink 2,19:border 0
20 dim p(80):mm=12:dim act(mm):for i=1 to mm:act(i)=rnd*79+1:next
30 md=mm-2:dim del(md):for i=1 to md:del(i)=rnd*79+1:next
Line 1,385:
90 p(x)=p(x)+1:if p(x)=50 then p(x)=0:del(i)=rnd*79+1
100 next:frame
110 goto 40</langsyntaxhighlight>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">SeedRandom[1234];
ClearAll[ColorFunc]
chars = RandomSample[Flatten[CharacterRange @@@ Partition[Characters["\[CapitalAlpha]\[CapitalPi]ЀѵҊԯ\:03e2\:03efヲンⲀ⳩\[ForAll]∗℀℺⨀⫿"], 2]]];
Line 1,422:
,
{1000}
]</langsyntaxhighlight>
{{out}}
Outputs a animating graphic of the matrix digital rain.
Line 1,429:
{{trans|C}}
{{libheader|nim-ncurses}}
<langsyntaxhighlight Nimlang="nim">import os, random, sequtils
import ncurses
 
Line 1,495:
refresh()
 
run()</langsyntaxhighlight>
 
=={{header|Perl}}==
Line 1,502:
Follow the bouncing Neo!
 
<langsyntaxhighlight lang="perl">#!/user/bin/perl
 
use strict;
Line 1,834:
';
}
</syntaxhighlight>
</lang>
===Another Perl Solution===
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # http://www.rosettacode.org/wiki/Matrix_Digital_Rain
Line 1,872:
@queue = grep $_->[2] > 0 && $_->[1] < $rows * 20, @queue, @new;
$mw->after( 63, \&step );
}</langsyntaxhighlight>
 
=={{header|Phix}}==
Line 1,878:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/matrix.htm here].
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Matrix_Digital_Rain.exw
Line 1,983:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</langsyntaxhighlight>-->
 
=={{header|Python}}==
<langsyntaxhighlight lang="python">
import curses
import random
Line 2,082:
except KeyboardInterrupt as err:
curses.endwin()
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
Line 2,088:
{{trans|Raku}}
 
<langsyntaxhighlight lang="racket">#lang racket
 
(define codes '((Α Π) (Ѐ ѵ) (Ҋ ԯ) (Ϣ ϯ) (ヲ ン) (Ⲁ ⳩) (∀ ∗) (℀ ℺) (⨀ ⫿)))
Line 2,132:
(display "\e[0m")
(display "\e[H\e[J\e[?25h"))])
(main))</langsyntaxhighlight>
 
=={{header|Raku}}==
Line 2,141:
The "lightning" effect is actually a bug, but I liked it so I kept it.
 
<syntaxhighlight lang="raku" perl6line># clean up on exit, reset ANSI codes, scroll, re-show the cursor & clear screen
signal(SIGINT).tap: { print "\e[0m", "\n" xx 50, "\e[H\e[J\e[?25h"; exit(0) }
 
Line 2,185:
@offset = (^@offset).map: {(@offset[$_] - ($_ % 3)) % +@palette};
}
}</langsyntaxhighlight>
 
{{out|Sample output}}
Line 2,193:
Digital rain note: &nbsp; This REXX program favors the use of Latin letters &nbsp; (both lower and uppercase) &nbsp; letters
over all others characters (glyphs) by a 25% factor.
<langsyntaxhighlight lang="rexx">/*REXX program creates/displays Matrix (the movie) digital rain; favors non-Latin chars.*/
signal on halt /*allow the user to halt/stop this pgm.*/
parse arg pc seed . /*obtain optional arguments from the CL*/
Line 2,237:
fogger: do f=1 for sw /*display a screen full of rain streams*/
if substr(cloud, f, 1) \== ' ' then cloud= overlay( drop(), cloud, f)
end /*f*/; call show; return /* [↑] if raindrop, then change drop. */</langsyntaxhighlight>
Programming note:
 
Line 2,322:
 
Cargo.toml
<langsyntaxhighlight lang="toml">
[package]
name = "matrix-digital-rain"
Line 2,331:
termion = "1.5.6"
rand = "0.8.5"
</syntaxhighlight>
</lang>
 
main.rs
<langsyntaxhighlight lang="rust">
#![warn(clippy::pedantic)] // make sure that clippy is even more annoying
 
Line 2,564:
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
</syntaxhighlight>
</lang>
 
=={{header|Wren}}==
Line 2,570:
{{libheader|DOME}}
The ''memory.ttf'' file is included with the DOME 'fonts' example and can be downloaded from [https://github.com/domeengine/dome/blob/main/examples/fonts/memory.ttf here].
<langsyntaxhighlight lang="ecmascript">import "dome" for Window
import "graphics" for Canvas, Color, Font
import "random" for Random
Line 2,640:
}
 
var Game = MatrixDigitalRain.new(640, 550)</langsyntaxhighlight>
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">open window 640,512,"swiss12"
backcolor 0,0,0
clear window
Line 2,697:
color r,g,b
text x*12.8,y*12.8,chr$(c)
end sub</langsyntaxhighlight>
 
=={{header|zkl}}==
{{trans|Raku}}
<langsyntaxhighlight lang="zkl">var [const] codes=Walker.chain( // a bunch of UTF non ascii chars
[0x0391..0x03a0], [0x03a3..0x0475], [0x0400..0x0475],
[0x048a..0x052f], [0x03e2..0x03ef], [0x2c80..0x2ce9],
Line 2,739:
}
return(o,s,fg);
}</langsyntaxhighlight>
Offsite Image: [http://www.zenkinetic.com/Images/RosettaCode/matrixRainDance.jpg Matrix rain dance]
 
Line 2,753:
The next step for this routine would be a way to randomise the length of the character trails (currently fixed at 12).
 
<langsyntaxhighlight lang="zxbasic">10 CLEAR 61999
20 BORDER 0: POKE 23624,4: POKE 23693,0: CLS: REM easier than "bright 0: flash 0: ink 0: paper 0"
30 PRINT INK 4; FLASH 1;"Initialising": GO SUB 9000: LET m=USR 62000: CLS: REM set up and run machine code; USR is the call function
Line 2,837:
9960 DATA "eof"
 
9999 POKE 23606,0: POKE 23607,60: INK 4: REM reset to default character set and colour if you get lost</langsyntaxhighlight>
 
Offsite Image: [https://imgur.com/sz6YkfI Spectrum rain at imgur]
10,333

edits