I want to run the Matrix.bat CMD with a different color on each line to make a rainbow effect.
Here is the Matrix.bat
@echo off
color ##
:start
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
goto :start
I have tried experimenting myself but have not succeeded with my low level experience. Here is where I got with my experimentation.
@echo off
:start
color 01
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
color 02
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
color 04
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
color 05
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
color 06
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%
goto :start
When I tried this it changed the whole command prompts color instead of the individual lines of %random%. Hopefully someone more experienced can give me some pointers on how to do this.
Best Answer
With Ansi escape codes, rapid, smooth and EASY rainbow (or other) matrix's can be achieved.
This linked code can alternate between the following outputs, with a very simple process to incorperate new output styles. I've remarked throughout the code what's being done and how / why.
the default: Smooth transitioning color changes (Waterfall like)
Rapid Chaotic color from one character to the next. flow is still smooth.
The matrix animation occurs in this code block:
The loop updates variables for cursor X and Y positions, the Character to be printed and the color to print it in using Random number Generation to access arrays for each non X Y value. Once those values are updated, they are expanded as arguments to the following Macro to action the ANSI codes changing position and color with the Echo command.
Inclusion of the
^&^&Endlocal
after performing the echo command is integral to preventing the setlocal recursion threshold being exceeded. Escaping the Ampersands prevent the Endlocal from destroying the macro during definition.The choice to use a macro to conduct the processing of arguments makes this script both smooth and Insanely Fast.
A variant modified to use character mapping through substring modification and random string lengths. The below variant also uses a method of assigning the ASCII 27 escape code to a variable, without requiring the actual ASCII 27 character.