News:

Welcome to RetroCoders Community

Main Menu

super simple Matrix Rain sub

Started by ron77, Aug 25, 2023, 02:48 PM

Previous topic - Next topic

ron77


here is a super simple Matrix Rain sub or function in freeBASIC...

'THIS IS A MATRIX PROGRAM, BY JOHN. W. SZCZEPANIAK
'' converted from qb to fb by ron77 2023-08-25

screenres 800, 600, 32 '12
width 800\8, 600\16

randomize

sub theMatrix()
    cls
    COLOR rgb(0, 255, 0)
    dim as long A, B, q, x
    A = 1
    B = 1
    DO
        q += 1
        IF q > 5 THEN
            q = 0
            LOCATE A, B
            PRINT CHR(x)
            A = int(RND * 36) + 1
            B = int(RND * 98) + 1
            x = int(RND * 227) + 28
            sleep 5
        end if
    LOOP UNTIL INKEY <> ""   ' = CHR(27)
        
    cls
    LOCATE 15, 30
    PRINT " THE MATRIX HAS YOU"
    sleep
end sub

theMatrix()

__blackjack__

`q` doesn't make any sense here.  Even in QBasic on an old DOS machine this would just cause a non noticeable delay.

`A`, `B`, and `x` are not really needed either.  All three are just used once, so we could just use the expressions used to define their values instead of the variables.

Instead of hard coding the limits of the random numbers for row and column it would be more flexible to query the number of rows and columns for the active screen mode.  Then it would also be possible to centre the message on the screen.

'THIS IS A MATRIX PROGRAM, BY JOHN. W. SZCZEPANIAK
' converted from qb to fb by ron77 2023-08-25
RANDOMIZE: SCREEN 19

DIM i AS LONG, rows AS INTEGER, columns AS INTEGER, text AS STRING

i = WIDTH: rows = HIWORD(i): columns = LOWORD(i)

COLOR 2  ' Green
DO
    LOCATE INT(RND * (rows - 1)) + 1, INT(RND * (columns - 1)) + 1
    PRINT CHR(INT(RND * 227) + 28)
    SLEEP 5  ' about 200 characters per second.
LOOP UNTIL INKEY <> ""  ' = CHR(27)

CLS
text = "THE MATRIX HAS YOU"
LOCATE rows \ 2, (columns - LEN(text)) \ 2
PRINT text
SLEEP

,,Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." —Brian W. Kernighan