Advertisement
T3RRYT3RR0R

batch fast Multicolor Matrix patterns

Apr 10th, 2020
3,893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 8.51 KB | None | 0 0
  1. @REM ::: ** This version is Obsolete. New version can be found: https://pastebin.com/yQkQ2SZ4
  2. :::
  3. ::: Batch Ansi based multi color matrix animations, featuring macro's.
  4. ::: explained within the code and in this answer here: https://stackoverflow.com/a/61147602/12343998
  5. ::: Updated to include an easily updated menu selection for different styles
  6.  
  7. ::: Youtube video: https://www.youtube.com/watch?v=4U2AKemEvBE
  8.  
  9. @Echo Off & CD "%~dp0"
  10.    
  11.     Set "AlignFile=%~dpnx0"
  12.  
  13.     Setlocal DisableDelayedExpansion
  14.  
  15.     (Set LF=^
  16.  
  17.  
  18.     %= NewLine =%)
  19.  
  20.     Set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  21.  
  22. %= cursor Positiong bookends used to prevent ansi escape code disrupting macro during definition =%
  23.     Set "[=["
  24.     Set "]=H"
  25.  
  26. %= Color Macro Variables =%
  27.  
  28.     Set @P=for /L %%n in (1 1 2) do if %%n==2 (%\n%
  29.         For /F "tokens=1,2,3 delims=, " %%G in ("!argv!") do (%\n%
  30.             Echo(![!%%G!]!!%%I!!%%H!!Off!^&^&Endlocal%\n%
  31.         ) %\n%
  32.     ) ELSE setlocal enableDelayedExpansion ^& set argv=,
  33.  
  34.     Setlocal EnableDelayedExpansion
  35.     Set /A Red=31,Green=32,Yellow=33,Blue=34,Purple=35,Cyan=36,White=37,Grey=90,Pink=91,Beige=93,Aqua=94,Magenta=95,Teal=96,Off=0,CI#=0
  36.     For %%A in (Red,Yellow,Green,Blue,Purple,Cyan,White,Grey,Pink,Beige,Aqua,Magenta,Teal,Off) do (
  37.         Set "%%A=[!%%A!m"
  38.         Set /A "CI#+=1"
  39.         Set "C#[!CI#!]=%%A"
  40.     )
  41.     Setlocal DisableDelayedExpansion
  42.  
  43.     Set "C1=A"
  44.     Set "C2=B"
  45.     Set "C3=C"
  46.     Set "C4=D"
  47.     Set "C5=E"
  48.     Set "C6=F"
  49.     Set "C7=G"
  50.     Set "C8=H"
  51.     Set "C9=I"
  52.     Set "C10=J"
  53.     Set "C11=K"
  54.     Set "C12=L"
  55.     Set "C13=M"
  56.     Set "C14=N"
  57.     Set "C15=O"
  58.     Set "C16=P"
  59.     Set "C17=Q"
  60.     Set "C18=R"
  61.     Set "C19=S"
  62.     Set "C20=T"
  63.     Set "C21=U"
  64.     Set "C22=V"
  65.     Set "C23=W"
  66.     Set "C24=X"
  67.     Set "C25=Y"
  68.     Set "C26=Z"
  69.     Set "C27=0"
  70.     Set "C28=1"
  71.     Set "C29=2"
  72.     Set "C30=3"
  73.     Set "C31=4"
  74.     Set "C32=5"
  75.     Set "C33=6"
  76.     Set "C34=7"
  77.     Set "C35=8"
  78.     Set "C36=9"
  79.     Set "C37=a"
  80.     Set "C38=b"
  81.     Set "C39=c"
  82.     Set "C40=d"
  83.     Set "C41=e"
  84.     Set "C42=f"
  85.     Set "C43=g"
  86.     Set "C44=h"
  87.     Set "C45=i"
  88.     Set "C46=j"
  89.     Set "C47=k"
  90.     Set "C48=l"
  91.     Set "C49=m"
  92.     Set "C50=n"
  93.     Set "C51=o"
  94.     Set "C52=p"
  95.     Set "C53=q"
  96.     Set "C54=r"
  97.     Set "C55=s"
  98.     Set "C56=t"
  99.     Set "C57=u"
  100.     Set "C58=v"
  101.     Set "C59=w"
  102.     Set "C60=x"
  103.     Set "C61=y"
  104.     Set "C62=z"
  105.     Set "C63=~"
  106.     Set "C64=&"
  107.     Set "C65=$"
  108.     Set "C66=@"
  109.     Set "C67=<"
  110.     Set "C68=>"
  111.     Set "C69=~"
  112.     Set "C70=^"
  113.     Set "C71=|"
  114.     Set "C72={"
  115.     Set "C73=}"
  116.     Set "C74=?"
  117.     Set "C75=/"
  118.     Set "C76=\"
  119.     Set "C77=["
  120.     Set "C78=["
  121.     Set "C79=+"
  122.     Set "C80=-"
  123.  
  124.     If Not "%~3"=="" (
  125.         Set "Console_Hieght=%~1"
  126.         Set "Console_Width=%~2"
  127.         Set "AlignFile=%~4"
  128.         Goto :%~3
  129.     ) Else (Goto :main)
  130.  
  131. %= Subroutine to process output of wmic command into usable variables  for screen dimensions (resolution) =%
  132.  
  133.     :ChangeConsole <Lines> <Columns> <Label to Resume From> <If a 4th parameter is Defined, Aligns screen at top left>
  134. %= Get screen Dimensions =%
  135.     For /f "delims=" %%# in  ('"wmic path Win32_VideoController  get CurrentHorizontalResolution,CurrentVerticalResolution /format:value"') do (
  136.         Set "%%#">nul
  137.     )
  138.  
  139. %= Calculation of X axis relative to screen resolution and console size =%
  140.  
  141.     Set /A CentreX= ( ( CurrentHorizontalResolution / 2 ) - ( %~2 * 4 ) ) + 8
  142.  
  143. %= Sub Optimal calculation of Y axis relative to screen resolution and console size =%
  144.     For /L %%A in (10,10,%1) DO Set /A VertMod+=1
  145.     Set /A CentreY= ( CurrentVerticalResolution / 4 ) - ( %~1 * Vertmod )
  146.     For /L %%B in (1,1,%VertMod%) do Set /A CentreY+= ( VertMod * 2 )
  147.  
  148. %= Optional 4th parameter can be used to align console at top left of screen instead of screen centre =%
  149.     If Not "%~4"=="" (Set /A CentreY=0,CentreX=-8)
  150.  
  151.     Set "Console_Width=%~2"
  152.  
  153. %= Creates a batch file to reopen the main script using Call with parameters to define properties for console change and the label to resume from =%
  154.         (
  155.         Echo.@Mode Con: lines=%~1 cols=%~2
  156.         Echo.@Title Rainbow Matrix by T3RRY
  157.         Echo.@Call "%AlignFile%" "%~1" "%~2" "%~3" "%AlignFile%"
  158.         )>"%temp%\ChangeConsole.bat"
  159.  
  160. %= .Vbs script creation and launch to reopen batch with new console settings, combines with ChangeConsole.bat to control window size and position =%
  161.         (
  162.         Echo.Set objWMIService = GetObject^("winmgmts:\\.\root\cimv2"^)
  163.         Echo.Set objConfig = objWMIService.Get^("Win32_ProcessStartup"^)
  164.         Echo.objConfig.SpawnInstance_
  165.         Echo.objConfig.X = %CentreX%
  166.         Echo.objConfig.Y = %CentreY%
  167.         Echo.Set objNewProcess = objWMIService.Get^("Win32_Process"^)
  168.         Echo.intReturn = objNewProcess.Create^("%temp%\ChangeConsole.bat", Null, objConfig, intProcessID^)
  169.         )>"%temp%\Consolepos.vbs"
  170.  
  171. %= Starts the companion batch script to Change Console properties, ends the parent =%
  172.     Start "" "%temp%\Consolepos.vbs" & Exit
  173.  
  174. :main
  175. %= Remainder of Script examples the usage of Subroutines and macro's =%
  176.  
  177.  
  178. %= If a 4rd parameter is used, Console will be positioned at top left of screen =%
  179.  
  180.     Call :ChangeConsole 45 170 Matrix top
  181.    
  182. :Matrix
  183. Setlocal enableDelayedExpansion
  184.  
  185. %= Numbers higher than actual console hieght cause the the console to scroll. the higher the number, the smoother the scroll =%
  186. %= and the less dense the characters on screen will be. =%
  187.  
  188.     Set /A Console_Hieght*=2
  189.  
  190. %= Define menu options accessed with the choice command. Each option becomes a loop number equal to the errorlevel of the option. =%
  191.     Set "Opt1=(W)aterfall %yellow%Matrix"
  192.     Set "Opt2=(C)haos     %red%M%yellow%a%green%t%blue%r%purple%i%magenta%x"
  193.     Set "Opt3=%red%(%pink%R%magenta%)%purple%a%blue%i%aqua%n%cyan%b%green%o%yellow%w %red%painting"
  194.  
  195. %= Display the menu options =%
  196.  
  197.     Set "Opt1=(W)aterfall %cyan%Matrix"
  198.     Set "Opt2=(C)haos     %red%M%yellow%a%green%t%blue%r%purple%i%magenta%x"
  199.     Set "Opt3=%red%(%pink%R%magenta%)%purple%a%blue%i%aqua%n%cyan%b%green%o%yellow%w %red%painting"
  200.     Set "Opt4=(F)laming %yellow%Matrix"
  201.     %@P% 1;1 Opt1 blue
  202.     %@P% 2;1 Opt2 magenta
  203.     %@P% 3;1 Opt3 aqua
  204.     %@P% 4;1 Opt4 red
  205. %= Force selection of valid option, goto selected option as loop# =%
  206.     Choice /N /C WCRF /M ""
  207.     CLS & Goto :loop%Errorlevel%
  208.  
  209. :loop1
  210. TITLE Flow Matrix By T3RRY
  211. :1loop
  212.     For /L %%A in (1,1,125) do (
  213. %= lower for loop end value equals faster transition, higher equals slower. Result of nCI color variable not being expanded with new value during for loop =%
  214.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  215.         %@P% !Ypos!;!Xpos! C!Char! !C#[%nCI%]!
  216.     )
  217. Goto :1loop
  218.  
  219. :loop2
  220. TITLE Chaos Matrix By T3RRY
  221. :2loop
  222.     For /L %%A in (1,1,5000) do (
  223.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  224.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[%%B]!
  225.     )
  226. Goto :2loop
  227.  
  228. :loop3
  229. TITLE Rainbow painter By T3RRY
  230.     Set /A Console_Hieght=( Console_Hieght / 2 ) - 4
  231. :3loop
  232.     Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  233.     For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[%%B]!
  234. Goto :3loop
  235.  
  236. :loop4
  237. TITLE Flaming Matrix By T3RRY
  238. Set /A Console_Height= ( ( Console_Height / 5 ) * 3 ) - 10
  239. :4loop
  240.     For /L %%A in (1,1,200000) do (
  241.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  242.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[2]!
  243.         Set /A Xpos-=1,Ypos+=1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  244.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[1]!
  245.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  246.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[2]!
  247.         Set /A Xpos-=1,Ypos+=1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  248.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[1]!
  249.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  250.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[2]!
  251.         Set /A Xpos+=1,Ypos+=1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  252.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[1]!
  253.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  254.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[2]!
  255.         Set /A Xpos+=1,Ypos-=1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  256.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[1]!
  257.         Set /A Xpos=!random! %%!Console_Width! + 1,Ypos=!random! %%!Console_Hieght! + 1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  258.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[2]!
  259.         Set /A Xpos-=1,Ypos-=1,Char=!random! %%80 + 1,nCI=!random! %%!CI#! + 1
  260.         For %%B in (!nCI!) do %@P% !Ypos!;!Xpos! C!Char! !C#[1]!
  261.     )
  262. Goto :4loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement