Batch File variables for ASCII character animations

preview_player
Показать описание
This video discusses the use of variables in Windows Batch File ASCII character animations. In particular, it highlights the advantages of FOR loops to created and access the large numbers of variables needed for rows (e.g. set Row%I=ABC), and the substrings needed for column values (e.g. echo !Variable:~%i%!). This is illustrated in the code below for Matrix-style dripping characters.

rem --- Initialize.
setlocal EnableDelayedExpansion
color 0A
set /A "MaxX = 100"
set /A "MaxY = 50"
set /A "lines=MaxY+2","cols=MaxX+1"
mode con lines=%lines% cols=%cols%
set "CharSetWithSpaces= 01233456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
:PERPETUAL_LOOP
rem --- Build the top row.
set /A "TopRow = (TopRow + 1) %% (MaxY + 1)"
set "Row_%TopRow%="
for /L %%X in (1,1,%MaxX%) do (
set /A "i = !RANDOM! %% 70"
call set "Row_%%TopRow%%=!Row_%TopRow%!%%CharSetWithSpaces:~!i!,1%%"
)
rem --- Display Screen.
set /A "Top2 = TopRow + 1"
cls
for /L %%Y in (%TopRow%,-1,0) do echo(!Row_%%Y!
for /L %%Y in (%MaxY%,-1,%Top2%) do echo(!Row_%%Y!
goto :PERPETUAL_LOOP

(C) Copyright 2012 Mr Batch Files.
Рекомендации по теме
Комментарии
Автор

As requested Matrix code in video. Works on my Windows 7 PC, but some PCs and AVs may block batch files by default.

@echo off
prompt $g
rem
rem
rem M A T R I X
rem
rem
rem Minimalist batch file to display Matrix-style dripping characters.
rem The display looks best with an 8x12 font.
rem
rem Alex Tonnet - August 2012
rem
  title %~n0
  rem --- Initialize.
  setlocal EnableDelayedExpansion
  color 0A
  set /A "MaxX = 100"
  set /A "MaxY =  50"
  set /A "lines=MaxY+2", "cols=MaxX+1"
  mode con lines=%lines% cols=%cols%
  set
:PERPETUAL_LOOP
  rem --- Build the top row.
  set /A "TopRow = (TopRow + 1) %% (MaxY + 1)"
  set "Row_%TopRow%="
  for /L %%X in (1, 1, %MaxX%) do (
    set /A "i = !RANDOM! %% 70"
    call set "Row_%%TopRow%%=!Row_%TopRow%!%%CharSetWithSpaces:~!i!, 1%%"
  )
  rem --- Display Screen.
  set /A "Top2 = TopRow + 1"
  cls
  for /L %%Y in (%TopRow%, -1, 0)    do echo(!Row_%%Y!
  for /L %%Y in (%MaxY%, -1, %Top2%) do echo(!Row_%%Y!
goto :PERPETUAL_LOOP

MrBatchFiles