I just started learning Batch by myself and I was trying to make a matrix thing for fun. What I am trying to make is a Batch program that displays a "Matrix Digital Rain." Except, whenever a %random:~-1% number is EQU to another %random:~-1% (Destined Digit), it is supposed to display that destined digit in a different color. Visual Idea
It was fairly easy to do the matrix part; However, making one digit appear in a different color is a different dimension for a noob. So far I have succeeded in: making the matrix rain, making texts appear in different colors, and making a condition for a destined digit. Is this even possible?
**Problems are: ** A. How do I detect destined numbers from the matrix rain and make them appear as yellow (SEPARATELY) without visibly disrupting the matrix rain? B. How do I create more vertical lines of this?
I've attached links, from where I got answers from, below; Along with my current batch script. Custom # of %random% Digits: How to generate 4 digit random numbers in a batch file? Different Text Colors: How do I make one particular line of a batch file a different color then the others?
@echo off
color 02
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
cls
:start
Ping -l 1 -n 1 -w 1000 1.1.1.1 -4 1>nul 2>&1 REM"delay cause too fast"
set num1=%random:~-2%
set num2=%random:~-2%
set dn=%random:~-2%
if %num1% EQU %num2% (call :color 06 "%random:~-2% %dn% %random:~-2%" & goto start) else (echo %random:~-2% %dn% %random:~-2% & goto start)
:color
echo off
echo %DEL% > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
I've tried echo %random:~-1% . . . %dn% %random:~-1% but all it does is have one line of random numbers that occasionally turn yellow. It would be perfect if it could appear across different vertical lines randomly.
I'll be looking into arrays for now but I don't think I'll be getting it soon. Thank you in advance for answering!!! :D
Your code with ansi escape sequences and some more columns.
@echo off
SETLOCAL EnableDelayedExpansion
set numCols=8
for /F %%a in ('echo prompt $E ^| cmd') do set "ESC=%%a"
cls
set "off=%ESC%[m"
set "red=%ESC%[0;31m"
set "red_light=%ESC%[1;31m"
set "green=%ESC%[32m"
set "yellow=%ESC%[33m"
REM for /L %%i in (30 1 39) do (
REM echo %%i: %ESC%[0;%%im TEXT %OFF%
REM echo %%i: %ESC%[1;%%im TEXT %OFF%
REM )
:start
Ping -l 1 -n 1 -w 1000 1.1.1.1 -4 1>nul 2>&1 REM"delay cause too fast"
for /L %%n in (1 1 %numCols%) do (
set "col[%%n]=!random:~-2!"
)
if !col[1]! GTR !col[3]! (
set "col[1]=%yellow%!col[1]!%OFF%"
)
if !col[2]! GTR !col[3]! (
set "col[5]=%red%!col[5]!%OFF%"
)
set "line="
for /L %%n in (1 1 %numCols%) do (
set "line=!line!!col[%%n]! "
)
echo !line!
goto :start