Matrix digital rain: Difference between revisions
m
Uploaded a new screenshot.
m (Uploaded a new screenshot.) |
|||
(25 intermediate revisions by 6 users not shown) | |||
Line 8:
=={{header|Ada}}==
Should work with ANSI terminals.
<
with Ada.Numerics.Discrete_Random;
with Ada.Strings.Fixed;
Line 100:
Put (ESC & "[49m"); -- Default backgound
Put (ESC & "[2J"); -- Clear Terminal
end Digital_Rain;</
=={{header|Amazing Hopper}}==
{{Trans|BASIC}}
<p>VERSION 1:</p>
<syntaxhighlight lang="c">
#include <basico.h>
#proto desplegarmatrixrain(_X_,_Y_,_Z_,_W_)
algoritmo
permitir interrupción
dimensionar (80) matriz aleatoria entera ( -50, t )
y=0
color(232,232)
borrar pantalla
enfatizado
iterar
iterar para(i=1, #(i<=80), ++i )
cuando ( #(t[i]>50) ){ #(t[i]=0) }
#basic{
t[i] += 1
y = t[i]
desplegar matrix rain(232,232,i,(y-10))
desplegar matrix rain(22,232,i,(y-9))
desplegar matrix rain(22,232,i,(y-8))
desplegar matrix rain(22,232,i,(y-7))
desplegar matrix rain(28,232,i,(y-6))
desplegar matrix rain(28,232,i,(y-5))
desplegar matrix rain(34,232,i,(y-4))
desplegar matrix rain(34,232,i,(y-3))
desplegar matrix rain(40,232,i,(y-2))
desplegar matrix rain(46,232,i,(y-1))
desplegar matrix rain(232,40,i,y)
}
siguiente
microsegundos(5000)
hasta que una tecla sea presionada
color(7,0)
borrar pantalla
terminar
subrutinas
desplegar matrix rain(p,s,x,y)
si ( y, está entre-excluyendo-(0,41) )
color (p,s)
imprimir en ( y,x, #(utf8(chr(33+((x*y) % 200)) )) )
fin si
retornar
</syntaxhighlight>
{{out}}
<pre>
semejante a la imagen de la VERSION 2, pero con menos "cola"
</pre>
<p>VERSION 2:</p>
<syntaxhighlight lang="c">
#include <basico.h>
#proto desplegarmatrixrain(_X_,_Y_)
algoritmo
dimensionar con (80) matriz aleatoria entera ( -50, t )
matrices (ctexto, cfondo)
'232,22,22,22,22,28,28,28,34,34,40,40,46,232' enlistar en 'ctexto'
'232,232,232,232,232,232,232,232,232,232,232,232,232,40' enlistar en 'cfondo'
color(232,232)
borrar pantalla
enfatizado
iterar
iterar para(i=1, #(i<=80), ++i )
cuando ( #(t[i]>53) ){ #(t[i]=rand(-50)) }
#basic{
t[i] += 1
desplegar matrix rain(i,t[i])
}
siguiente
microsegundos(50000)
hasta que una tecla sea presionada
color(7,0)
borrar pantalla
terminar
subrutinas
desplegar matrix rain(x,y)
i=13, j=1
iterar
si ( #(y-i), está entre-excluyendo-(0,41) )
color ( #(ctexto[j]), #(cfondo[j]) )
imprimir en ( #(y-i),x, #(utf8(chr(33+((x*(y-i)) % 200)) )) )
fin si
--i, ++j
mientras ' no es negativo(i)'
retornar
</syntaxhighlight>
{{out}}
[[File:Matrix_rain_terminal_linux_2.png]]
=={{header|BASIC}}==
==={{header|FreeBASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="vb">Sub d(p As Ulong, s As Ulong, x As Long, y As Long)
Color p, s
If y > 0 And y < 24 Then Locate y, x: Print Chr(33 + (x * y) Mod 200);
End Sub
Dim As Long t(80)
For i As Integer = 1 To 80
t(i) = Int(-50 * Rnd)
Next
Dim As Double s = Timer
Cls
Do
For i As Integer = 1 To 80
If t(i) > 28 Then t(i) = 0
t(i) += 1
Dim As Long 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 - 2)
d(11, 0, i, y - 1)
d( 0, 2, i, y)
Next i
Dim As Double l = Timer
While l = Timer: Wend
Loop</syntaxhighlight>
==={{header|QBasic}}===
Original code programmed by nitro2k01
[https://codegolf.stackexchange.com/questions/17285/make-the-matrix-digital-rain-using-the-shortest-amount-of-code]<syntaxhighlight lang="qbasic">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</syntaxhighlight>
==={{header|True BASIC}}===
{{trans|QBasic}}
<syntaxhighlight lang="qbasic">SUB d (p,s,x,y)
SET COLOR p
SET BACKGROUND COLOR s
IF y > 0 AND y < 24 THEN
SET CURSOR y, x
PRINT CHR$(33+REMAINDER((x*y),200));
END IF
END SUB
DIM t(80)
FOR i = 1 TO 80
LET t(i) = INT(-50*RND)
NEXT i
LET s = TIME
CLEAR
DO
FOR i = 1 TO 80
IF t(i) > 28 THEN LET t(i) = 0
LET t(i) = t(i)+1
LET y = t(i)
CALL d (0, 0, i, y-6)
CALL d (2, 0, i, y-5)
CALL d (2, 0, i, y-4)
CALL d (10, 0, i, y-2)
CALL d (11, 0, i, y-1)
CALL d (0, 2, i, y)
NEXT i
LET l = TIME
DO WHILE l = TIME
LOOP
LOOP
END</syntaxhighlight>
=={{header|Batch File}}==
{{Works with|Windows 10}}
This code uses Windows 10 VT100 escape sequences.
<
:: Batch File Implementation
Line 152 ⟶ 373:
<nul set /p "=%esc%[1T%esc%[1;1H" %== scroll down and set cursor position to home ==%
echo(%disp_line%
goto matrix_loop</
=={{header|C}}==
Line 173 ⟶ 394:
And here's the code :
<syntaxhighlight lang="c">
/**
* Loosely emulates the "digital rain" effect from The Matrix.
Line 296 ⟶ 517:
return 0;
}
</syntaxhighlight>
===Microsoft Windows console version===
====Single threaded====
{{Works with|Microsoft Visual Studio C}}
<
*
* Digital ASCII rain - the single thread variant.
Line 484 ⟶ 705:
return 0;
}</
====Multiple threads====
{{Works with|Microsoft Visual Studio C}}
<
*
* Digital ASCII rain - multithreaded.
Line 691 ⟶ 912:
return 0;
}</
====Fibers====
{{Works with|Microsoft Visual Studio C}}
<
*
* Digital ASCII rain - multithreaded.
Line 890 ⟶ 1,111:
return 0;
}</
=={{header|Common Lisp}}==
Line 898 ⟶ 1,119:
Runs in the terminal (using the Ncurses C library and the croatoan Lisp wrapper).
<
(defun matrix-digital-rain ()
(with-screen (scr :input-echoing nil :input-blocking nil :cursor-visible nil)
Line 931 ⟶ 1,152:
(setf (frame-rate scr) 20)
(run-event-loop scr))))
</syntaxhighlight>
{{out|Sample output}}
Line 941 ⟶ 1,162:
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.
<
import (
Line 1,046 ⟶ 1,267:
}
}
}</
=={{header|J}}==
Line 1,053 ⟶ 1,274:
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...
<
coinsert'jgl2'
Line 1,064 ⟶ 1,285:
rows=: i.0
scale=: 24
live=: (#heat)#<i.
try.
wd 'psel rain'
glsel 'green'
glfill 0 0 0 255
glfont font=.'courier ',":0.8*scale
upd=. 0>._3++/?2 2 2 2 4
cols=: cols,upd{.(?~{.sz)-.(-<.0.3*{:sz){.cols
rows=: (#cols){.rows
live=: }.live,<(scale*cols,.rows),.?(#cols)##junk
for_p. live do.
gltextcolor glrgb p_index{heat
if.p_index=<:#live do.
glfont font,' bold'
end.
for_xyj.;p do.
gltextxy 2{.xyj
gltext 8 u:junk{~{:xyj
end.
end.
keep=:
cols=: keep#cols
rows=: keep#rows+1
EMPTY
catch.
wd'ptimer 0'
end.
}}
wd rplc&('DIMS';":scale*sz) {{)n
Line 1,095 ⟶ 1,322:
cc green isidraw flush;
pshow;
}}</
[[File:J-matrix-digital-rain.png|thumb]]
Notes:
<tt>
In the movie, the display was somewhat pixelated, and had some other artifacts which were characteristic of cathode display tubes. The font support we use here does not emulate all of that.
Conceptually, we are emulating an emulation of a cathode ray tube with a long phosphor persistence time. Thus, there's an initial "burst" of light when the phosphor is being painted followed by a lingering glow which gradually fades out. Here, we use a <span style="background-color: black; color: #e0ffff"> light cyan </span> to represent the initial paint event and <span style="color: #00ff00">f</span><span style="color: #00ec00">a</span><span style="color: #00da00">d</span><span style="color: #00c900">i</span><span style="color: #00b900">n</span><span style="color: #00aa00">g</span><span style="color: #009b00"> </span><span style="color: #008d00">s</span><span style="color: #007f00">h</span><span style="color: #007200">a</span><span style="color: #006600">d</span><span style="color: #005b00">e</span><span style="color: #004f00">s</span><span style="color: #004500"> </span><span style="color: #003b00">o</span><span style="color: #003100">f</span><span style="color: #002800"> </span><span style="color: #001f00">g</span><span style="color: #001700">r</span><span style="color: #000f00">e</span><span style="color: #000700">e</span><span style="color: #000000">n</span> to represent the fading phosphors. To better approximate the phosphor persistence mechanism, we have intensity fall off exponentially (and then we adjust the numeric range of the result so it still fades from our brightest green to black).
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.swing.JFrame;
public final class MatrixDigitalRain {
public static void main(String[] args) {
EventQueue.invokeLater( () -> {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("Matrix Digital Rain");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
DigitalRain digitalRain = new DigitalRain(800, 600);
frame.add(digitalRain);
frame.setLocationByPlatform(true);
frame.pack();
frame.setVisible(true);
digitalRain.start();
} );
}
private static final class DigitalRain extends Canvas {
public DigitalRain(int aWidth, int aHeight) {
setPreferredSize( new Dimension(aWidth, aHeight) );
setBackground(Color.BLACK);
columnCount = aWidth / ( 2 * halfColumnWidth ) - 1;
rowCount = aHeight / ( 2 * halfFontSize );
setCursor(getToolkit().createCustomCursor(
new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB), new Point(0, 0), "transparent"));
executiveService = Executors.newSingleThreadExecutor();
random = ThreadLocalRandom.current();
}
public void start() {
requestFocus();
createBufferStrategy(2);
executiveService.execute( new DrawingCycle(rowCount) );
}
private final class DrawingCycle implements Runnable {
public DrawingCycle(int rowCount) {
columns = Stream.generate( () -> new Column(rowCount) )
.limit(columnCount).collect(Collectors.toList());
bufferStrategy = getBufferStrategy();
scheduler = Executors.newSingleThreadScheduledExecutor();
}
@Override
public void run() {
scheduler.scheduleAtFixedRate( () -> { draw(); update(); }, 0, 100, TimeUnit.MILLISECONDS);
}
private void draw() {
Graphics2D graphics2D = (Graphics2D) bufferStrategy.getDrawGraphics();
graphics2D.setColor(Color.BLACK);
graphics2D.fillRect(0, 0, getWidth(), getHeight());
for ( int col = 0; col < columnCount; col++ ) {
for ( int row = 0; row < rowCount; row++ ) {
Symbol symbol = columns.get(col).symbols.get(row);
graphics2D.setFont(symbol.font);
graphics2D.setColor(symbol.color());
final int size = symbol.font.getSize();
graphics2D.drawString(
symbol.element,
2 * halfColumnWidth * col + halfColumnWidth + ( 6 * halfFontSize - size ) / 2,
row * 2 * halfFontSize);
}
}
graphics2D.dispose();
bufferStrategy.show();
}
private void update() {
for ( Column column : columns ) {
if ( column.index >= 0 ) {
String element = elements.get(random.nextInt(elements.size()));
column.symbols.set(column.index, new Symbol(element, column.font, 255) );
}
column.index = Math.min(column.index + 1, rowCount);
column.darken();
if ( column.index == rowCount ) {
column.reset();
}
}
}
private final List<Column> columns;
private final BufferStrategy bufferStrategy;
private final ScheduledExecutorService scheduler;
} // End DrawingCycle class
private final class Column {
public Column(int aRowCount) {
rowCount = aRowCount;
index = random.nextInt(-rowCount, rowCount);
setFont();
symbols = Stream.generate( () -> new Symbol(font) ).limit(rowCount).collect(Collectors.toList());
}
public void darken() {
symbols.stream().forEach(Symbol::darken);
}
public void reset() {
index = random.nextInt(-rowCount, rowCount / 2);
setFont();
}
private void setFont() {
final int fontSize = ( random.nextInt(2) == 0 ) ?
2 * halfFontSize : ( random.nextInt(2) == 0 ) ?
(int) ( 1.5 * halfFontSize ) : 3 * halfFontSize;
final int fontStyle = ( random.nextInt(3) == 0 ) ? Font.BOLD : Font.PLAIN;
font = new Font("Dialog", fontStyle, fontSize);
}
private int index;
private Font font;
private List<Symbol> symbols;
private final int rowCount;
} // End Column class
private final class Symbol {
public Symbol(String aElement, Font aFont, int aBrightness) {
element = aElement;
font = aFont;
brightness = aBrightness;
}
public Symbol(Font font) {
this(" ", font, 0);
}
public Color color() {
return new Color(0, 255, 0, brightness);
}
public void darken() {
brightness = Math.max(0, brightness - 5);
}
public String toString() {
return element;
}
private int brightness;
private final Font font;
private final String element;
} // End Symbol class
private final int columnCount;
private final int rowCount;
private final ExecutorService executiveService;
private final int halfFontSize = 6;
private final int halfColumnWidth = 10;
private final ThreadLocalRandom random;
private final List<String> elements = List.of(
"M", "Ї", "Љ", "Њ", "Ћ", "Ќ", "Ѝ", "Ў", "Џ", "Б", "Г", "Д", "Ж", "И", "Й", "Л", "П", "Ф", "Ц", "Ч", "Ш",
"Щ", "Ъ", "Ы", "Э", "Ю", "Я", "в", "д", "ж", "з", "и", "й", "к", "л", "м", "н", "п", "т", "ф", "ц", "ч",
"ш", "щ", "ъ", "ы", "ь", "э", "ю", "я", "ѐ", "ё", "ђ", "ѓ", "є", "ї", "љ", "њ", "ћ", "ќ", "ѝ", "ў", "џ",
"Ѣ", "ѣ", "ѧ", "Ѯ", "ѱ", "Ѳ", "ѳ", "ҋ", "Ҍ", "ҍ", "Ҏ", "ҏ", "Ґ", "ґ", "Ғ", "ғ", "Ҕ", "ҕ", "Җ", "җ", "Ҙ",
"ҙ", "Қ", "қ", "ҝ", "ҟ", "ҡ", "Ң", "ң", "Ҥ", "ҥ", "ҩ", "Ҫ", "ҫ", "Ҭ", "ҭ", "Ұ", "ұ", "Ҳ", "ҳ", "ҵ", "ҷ",
"ҹ", "Һ", "ҿ", "Ӂ", "ӂ", "Ӄ", "ӄ", "ӆ", "Ӈ", "ӈ", "ӊ", "Ӌ", "ӌ", "ӎ", "Ӑ", "ӑ", "Ӓ", "ӓ", "Ӕ", "ӕ", "Ӗ",
"ӗ", "Ә", "ә", "Ӛ", "ӛ", "Ӝ", "ӝ", "Ӟ", "ӟ", "ӡ", "Ӣ", "ӣ", "Ӥ", "ӥ", "Ӧ", "ӧ", "Ө", "ө", "Ӫ", "ӫ", "Ӭ",
"ӭ", "Ӯ", "ӯ", "Ӱ", "ӱ", "Ӳ", "ӳ", "Ӵ", "ӵ", "Ӷ", "ӷ", "Ӹ", "ӹ", "Ӻ", "ӽ", "ӿ", "Ԁ", "ԍ", "ԏ", "Ԑ", "ԑ",
"ԓ", "Ԛ", "ԟ", "Ԧ", "ԧ", "Ϥ", "ϥ", "ϫ", "ϭ", "ゥ", "ェ", "ォ", "ャ", "ュ", "ョ", "ッ", "ー", "ア", "イ", "ウ", "エ",
"オ", "カ", "キ", "ク", "ケ", "コ", "サ", "シ", "ス", "セ", "ソ", "タ", "チ", "ツ", "テ", "ト", "ナ", "ニ", "ヌ", "ネ", "ノ",
"ハ", "ヒ", "フ", "ヘ", "ホ", "マ", "ミ", "ム", "メ", "モ", "ヤ", "ユ", "ヨ", "ラ", "リ", "ル", "レ", "ロ", "ワ", "ン", "ⲁ",
"Ⲃ", "ⲃ", "Ⲅ", "Γ", "Δ", "Θ", "Λ", "Ξ", "Π", "Ѐ", "Ё", "Ђ", "Ѓ", "Є", "ⲉ", "Ⲋ", "ⲋ", "Ⲍ", "ⲍ", "ⲏ", "ⲑ",
"ⲓ", "ⲕ", "ⲗ", "ⲙ", "ⲛ", "Ⲝ", "ⲝ", "ⲡ", "ⲧ", "ⲩ", "ⲫ", "ⲭ", "ⲯ", "ⳁ", "Ⳉ", "ⳉ", "ⳋ", "ⳤ", "⳥", "⳦", "⳨",
"⳩", "∀", "∁", "∂", "∃", "∄", "∅", "∆", "∇", "∈", "∉", "∊", "∋", "∌", "∍", "∎", "∏", "∐", "∑", "∓",
"ℇ", "ℏ", "℥", "Ⅎ", "ℷ", "⩫", "⨀", "⨅", "⨆", "⨉", "⨍", "⨎", "⨏", "⨐", "⨑", "⨒", "⨓", "⨔", "⨕", "⨖",
"⨗", "⨘", "⨙", "⨚", "⨛", "⨜", "⨝", "⨿", "⩪" );
} // End DigitalRain class
} // End MatrixDigitalRain class
</syntaxhighlight>
{{ out }}
A screenshot from the running program.
[[Media: JavaMatrixDigitalRain.png]]
=={{header|Javascript}}==
El código es de Christian Behler (christian@pingpoli.de)
<
// a higher fade factor will make the characters fade quicker
var fadeFactor = 0.05;
Line 1,239 ⟶ 1,686:
fadeFactor = Math.min(Math.max(document.getElementById("fadeFactor").value , 0.0) , 1.0);
initMatrix();
}</
Html to test:
<pre><!DOCTYPE html>
Line 1,278 ⟶ 1,725:
=={{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.
<
import Base.iterate, Base.IteratorSize, Base.IteratorEltype
Line 1,359 ⟶ 1,806:
digitalrain()
</syntaxhighlight>
=={{header|Locomotive Basic}}==
<
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 ⟶ 1,820:
90 p(x)=p(x)+1:if p(x)=25 then p(x)=0:del(i)=rnd*19+1
100 next
110 goto 40</
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:
<
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 ⟶ 1,832:
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</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
ClearAll[ColorFunc]
chars = RandomSample[Flatten[CharacterRange @@@ Partition[Characters["\[CapitalAlpha]\[CapitalPi]ЀѵҊԯ\:03e2\:03efヲンⲀ⳩\[ForAll]∗℀℺⨀⫿"], 2]]];
Line 1,422 ⟶ 1,869:
,
{1000}
]</
{{out}}
Outputs a animating graphic of the matrix digital rain.
Line 1,429 ⟶ 1,876:
{{trans|C}}
{{libheader|nim-ncurses}}
<
import ncurses
Line 1,495 ⟶ 1,942:
refresh()
run()</
=={{header|Perl}}==
Line 1,502 ⟶ 1,949:
Follow the bouncing Neo!
<
use strict;
Line 1,834 ⟶ 2,281:
';
}
</syntaxhighlight>
===Another Perl Solution===
<
use strict; # http://www.rosettacode.org/wiki/Matrix_Digital_Rain
Line 1,872 ⟶ 2,319:
@queue = grep $_->[2] > 0 && $_->[1] < $rows * 20, @queue, @new;
$mw->after( 63, \&step );
}</
=={{header|Phix}}==
Line 1,878 ⟶ 2,325:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/matrix.htm here].
<!--<
<span style="color: #000080;font-style:italic;">--
-- demo\rosetta\Matrix_Digital_Rain.exw
Line 1,983 ⟶ 2,430:
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</
=={{header|Python}}==
<
import curses
import random
Line 2,082 ⟶ 2,529:
except KeyboardInterrupt as err:
curses.endwin()
</syntaxhighlight>
=={{header|Racket}}==
Line 2,088 ⟶ 2,535:
{{trans|Raku}}
<
(define codes '((Α Π) (Ѐ ѵ) (Ҋ ԯ) (Ϣ ϯ) (ヲ ン) (Ⲁ ⳩) (∀ ∗) (℀ ℺) (⨀ ⫿)))
Line 2,132 ⟶ 2,579:
(display "\e[0m")
(display "\e[H\e[J\e[?25h"))])
(main))</
=={{header|Raku}}==
Line 2,141 ⟶ 2,588:
The "lightning" effect is actually a bug, but I liked it so I kept it.
<syntaxhighlight lang="raku"
signal(SIGINT).tap: { print "\e[0m", "\n" xx 50, "\e[H\e[J\e[?25h"; exit(0) }
Line 2,185 ⟶ 2,632:
@offset = (^@offset).map: {(@offset[$_] - ($_ % 3)) % +@palette};
}
}</
{{out|Sample output}}
Line 2,193 ⟶ 2,640:
Digital rain note: This REXX program favors the use of Latin letters (both lower and uppercase) letters
over all others characters (glyphs) by a 25% factor.
<
signal on halt /*allow the user to halt/stop this pgm.*/
parse arg pc seed . /*obtain optional arguments from the CL*/
Line 2,237 ⟶ 2,684:
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. */</
Programming note:
Line 2,322 ⟶ 2,769:
Cargo.toml
<
[package]
name = "matrix-digital-rain"
Line 2,331 ⟶ 2,778:
termion = "1.5.6"
rand = "0.8.5"
</syntaxhighlight>
main.rs
<
#![warn(clippy::pedantic)] // make sure that clippy is even more annoying
Line 2,564 ⟶ 3,011:
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
</syntaxhighlight>
=={{header|Wren}}==
Line 2,570 ⟶ 3,017:
{{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].
<
import "graphics" for Canvas, Color, Font
import "random" for Random
Line 2,640 ⟶ 3,087:
}
var Game = MatrixDigitalRain.new(640, 550)</
=={{header|Yabasic}}==
<
backcolor 0,0,0
clear window
Line 2,697 ⟶ 3,144:
color r,g,b
text x*12.8,y*12.8,chr$(c)
end sub</
=={{header|zkl}}==
{{trans|Raku}}
<
[0x0391..0x03a0], [0x03a3..0x0475], [0x0400..0x0475],
[0x048a..0x052f], [0x03e2..0x03ef], [0x2c80..0x2ce9],
Line 2,739 ⟶ 3,186:
}
return(o,s,fg);
}</
Offsite Image: [http://www.zenkinetic.com/Images/RosettaCode/matrixRainDance.jpg Matrix rain dance]
Line 2,753 ⟶ 3,200:
The next step for this routine would be a way to randomise the length of the character trails (currently fixed at 12).
<
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 ⟶ 3,284:
9960 DATA "eof"
9999 POKE 23606,0: POKE 23607,60: INK 4: REM reset to default character set and colour if you get lost</
Offsite Image: [https://imgur.com/sz6YkfI Spectrum rain at imgur]
|