A special visual effect code: The Matrix

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
neorobin
Posts: 47
Joined: 01 May 2012 12:18

A special visual effect code: The Matrix

#1 Post by neorobin » 02 Jun 2012 14:20

Image
The attachment for the special chars version(not compatible with WIN7): http://115.com/file/e78zm09o#TheMatrix.rar

The code below (normal chars) tested under XP (compatible with WIN7, but can't FullScreen).

Code: Select all

@echo off & title The Matrix & setlocal enabledelayedexpansion
for /f "tokens=2 delims=[]" %%a in ('ver') do for /f "tokens=2 delims=. " %%a in ("%%a") do set /a "FullScreen=-((%%a-6)>>31)"

if "%1"=="" (
  for %%a in (FontSize:00080008 FontFamily:00000030 WindowSize:00320050 ScreenColors:0000000a CodePage:000001b5 ScreenBufferSize:00320050 FullScreen:!FullScreen!
  ) do for /f "tokens=1,2 delims=:" %%b in ("%%a") do (
    >nul reg add HKCU\Console\TheMatrix /v %%b /t reg_dword /d 0x%%c /f
  )
  start "TheMatrix" /max "%ComSpec%" /c "%~f0" 1 & exit
) else ( >nul reg delete HKCU\Console\TheMatrix /f )

set "Matrix="
set /a "wid=80,hei=50,iMax=wid*hei, sumOfStream=wid*2/2"
for /l %%i in (1 1 !iMax!) do set "Matrix= !Matrix!"
set "bss=!Matrix: =!"

set "dic=~@#$&*()_+{}|<>?`[]\;',./1234567890"
set "dicLen=35"

for /l %%# in (1 1 !wid!) do set "s%%#=0"
for /l %%* in (0 0 0) do (
  for /l %%# in (1 1 !sumOfStream!) do (
    if !s%%#! leq 1 (
      set /a "h%%#=!random!%%(hei-1)+2,p0%%#=!random!%%(wid*(hei+1-h%%#))+1,l%%#=h%%#+!random!%%hei+1,s%%#=l%%#+h%%#,h%%#+=1,p%%#=p0%%#"
    )
    set /a "s%%#-=1,l%%#-=1,h%%#-=1,old=(l%%#-1)>>31,grow=-h%%#>>31,act=grow|old,old0=-^!l%%#,p%%#=(old0&p0%%#)|(~old0&p%%#)"

    if !act! neq 0 (
      set /a "lL=p%%#-1, lR=iMax-p%%#, r=!random! %% dicLen"
      if !old! neq 0 (set "chr= ") else for %%r in (!r!) do set "chr=!dic:~%%r,1!"
      for /f "tokens=1-3" %%a in ("!lL! !p%%#! !lR!") do (set "Matrix=!Matrix:~0,%%a!!chr!!Matrix:~%%b,%%c!")
      set /a "p%%#+=wid"
    )
  )
  cls & <nul set /p "=!Matrix:~0,-1!!bss!"
)
exit


abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: A special visual effect code: The Matrix

#2 Post by abc0502 » 03 Jun 2012 17:07

8)
nice code

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: A special visual effect code: The Matrix

#3 Post by Ed Dyreen » 30 Oct 2012 01:20

Hi Neorobin,

I rewrote it with a much simpler and less obfuscated algo.
I would have to take the set/a part apart because I don't think it's "good style".
Try to avoid the backSpace can cause flicker :idea:

TheMatrix.CMD

Code: Select all

@echo off &setlocal enableDelayedExpansion &title %~n0 &color 0A


set /a $cols    = 80
set /a $lines   = 50

set        "$dictionary=~@#$&*()_+{}|<>?`[]\;',./1234567890"
set "$dictionary.length=35"

mode.COM con cols=!$cols! lines=!$lines! 2>nul
cmdow.EXE /fs 2>nul

set /a $cols  -= 2
set /a $lines -= 1

for /l %%? in () do (
       ::
       if !$stringsActive! lss !$cols! (
              ::
              set /a $activateString = !random! %% !$cols!
              ::
              for %%? in (

                     !$activateString!

              ) do   if !$string[%%?]! lss 1 (

                     set /a $string[%%?]    = !random! %% !$lines! + 1
                     set /a $stringsActive += 1
              )
       )
       ::
       set /a $ = !$lines! &for /l %%§ in (

              !$lines!, -1, 2

       ) do   set /a $ -= 1 &for %%? in (

              !$!

       ) do   set "$line[%%§]=!$line[%%?]!"

       set "$line[1]=" &for /l %%? in (

              1, 1, !$cols!

       ) do   if !$string[%%?]! gtr 0 (

              set /a $string[%%?] -= 1 &if !$string[%%?]! lss 1 (
                     ::
                     set /a $stringsActive -= 1
              )

              set /a $char = !random! %% $dictionary.length &for %%? in (

                     !$char!

              ) do   set "$line[1]=!$line[1]!!$dictionary:~%%?,1!"

       ) else set "$line[1]=!$line[1]! "

       set "$raster=" &for /l %%? in (

              1, 1, !$lines!

       ) do   set "$raster=!$raster! !$line[%%?]! "

       cls
       echo. $stringsActive=!$stringsActive!_
       <nul set /p "=!$raster:~0,-1!"
)
Just for fun I used QBFCompiler and renamed TheMatrix.EXE to TheMatrix.SCR. We have a real screensaver LoL :lol:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: A special visual effect code: The Matrix

#4 Post by Ed Dyreen » 30 Oct 2012 03:17

This one hovers a text of choice hehe :roll:

Code: Select all

@echo off &setlocal enableDelayedExpansion &title %~n0 &color 0A


set /a $cols    = 80
set /a $lines    = 25

set        "$dictionary=~@#$&*()_+{}|<>?`[]\;',./1234567890"
set "$dictionary.length=35"

for /l %%? in ( 1, 1, !$cols! ) do set "$spacer=!$spacer! "
for /l %%? in ( 1, 1, !$lines! ) do set "$line[%%?]=!$spacer!"

mode.COM con cols=!$cols! lines=!$lines! 2>nul
::cmdow.EXE /fs 2>nul

set /a $cols    -= 2
set /a $lines    -= 1

set "$ed[1]=!$spacer!  #   #   #   EEEEE DDD     DDD   Y    Y RRRR  EEEEE EEEEE N   N   #   #   #  "
set "$ed[2]=!$spacer!  #   #   #   E     D  D    D  D   Y  Y  R   R E     E     NN  N   #   #   #  "
set "$ed[3]=!$spacer!  #   #   #   EEEEE D   D   D   D   YY   RRRR  EEEEE EEEEE N N N   #   #   #  "
set "$ed[4]=!$spacer!  #   #   #   E     D  D    D  D    Y    R  R  E     E     N  NN   #   #   #  "
set "$ed[5]=!$spacer!  @   @   @   EEEEE DDD     DDD    Y     R   R EEEEE EEEEE N   N   @   @   @  "

for /l %%? in () do (

   :: activate a randomly column if not already
   rem (
      if !$strings! lss !$cols! (
         ::
         set /a $activateString = !random! %% !$cols!
         ::
         for %%? in (

            !$activateString!

         ) do    if !$string[%%?]! lss 1 (

            set /a $string[%%?]    = !random! %% !$lines! + 1
            set /a $strings += 1
         )
      )
   rem )

   :: build array[memory]
   rem (
      set /a $ = !$lines! &for /l %%§ in (

         !$lines!, -1, 2

      ) do    set /a $ -= 1 &for %%? in (

         !$!

      ) do    set "$line[%%§]=!$line[%%?]!"
   rem )

   :: build array[1]
   rem (
      set "$line[1]=" &for /l %%? in (

         1, 1, !$cols!

      ) do    if !$string[%%?]! gtr 0 (

         set /a $string[%%?] -= 1 &if !$string[%%?]! lss 1 (
            ::
            set /a $strings -= 1
         )

         set /a $char = !random! %% $dictionary.length &for %%? in (

            !$char!

         ) do    set "$line[1]=!$line[1]!!$dictionary:~%%?,1!"

      ) else    set "$line[1]=!$line[1]! "
   rem )

   :: hover $ed[*]
   rem (
      for /l %%§ in (

         1, 1, 6

      ) do    set "$ed[%%§]=!$ed[%%§]:~1!!$ed[%%§]:~0,1!
   rem )

   :: combine[1-6], $line[1-6]
   rem (
      set "$combine[1]=$strings(!$strings!)!$spacer!"
      set "$combine[10]=!$ed[1]!!$spacer!"
      set "$combine[11]=!$ed[2]!!$spacer!"
      set "$combine[12]=!$ed[3]!!$spacer!"
      set "$combine[13]=!$ed[4]!!$spacer!"
      set "$combine[14]=!$ed[5]!!$spacer!"
      ::
      for %%§ in (

         1, 10, 11, 12, 13, 14

      ) do    set "$combine[%%§]=!$combine[%%§]:~0,%$cols%!" &for /l %%? in (

         0, 1, !$cols!

      ) do    set /a $ = %%? + 1 &for %%@ in (

         !$!

      ) do    if "!$combine[%%§]:~%%?,1!" == " " (

         set "$combine[%%§]=!$combine[%%§]:~0,%%?!!$line[%%§]:~%%?,1!!$combine[%%§]:~%%@!"
      )

      for /l %%? in (

         2, 1, 9

      ) do    set "$combine[%%?]=!$line[%%?]!"

      for /l %%? in (

         15, 1, !$lines!

      ) do    set "$combine[%%?]=!$line[%%?]!"

   rem )

   :: build raster
   rem (
      set "$raster="

      for /l %%? in (

         1, 1, !$lines!

      ) do    set "$raster=!$raster! !$combine[%%?]! "
   rem )

   :: print raster
   rem (
      cls &<nul set /p "=!$raster:~0,-1!"
   rem )
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: A special visual effect code: The Matrix

#5 Post by foxidrive » 30 Oct 2012 04:00

That one's not so good here in Win7 32 bit.

Image

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: A special visual effect code: The Matrix

#6 Post by foxidrive » 30 Oct 2012 04:06

Ed Dyreen wrote:Hi Neorobin,

I rewrote it with a much simpler and less obfuscated algo.
I would have to take the set/a part apart because I don't think it's "good style".
Try to avoid the backSpace can cause flicker :idea:

TheMatrix.CMD


This one has a running string on line one column 1 that is updated. Win7 32 bit.
It's a nice effort but not as polished as Neorobin's.

Neorobin's works fine in Win7 32 bit too.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: A special visual effect code: The Matrix

#7 Post by Ed Dyreen » 30 Oct 2012 05:40

foxidrive wrote:That one's not so good here in Win7 32 bit.
set /p obviously works different on win7. :|
foxidrive wrote:Neorobin's works fine in Win7 32 bit too.
With me winXP, it flickers due to the backSpace.

Boombox
Posts: 80
Joined: 18 Oct 2012 05:51

Re: A special visual effect code: The Matrix

#8 Post by Boombox » 30 Oct 2012 05:54

.

Code: Select all

set /a $ = !$lines! &for /l %%§ in (

              !$lines!, -1, 2

) do   set /a $ -= 1 &for %%? in (


One of many parts of this code that confuse me...

1: Are these characters used for any reason, other than, because you can? § $

2: And why do many of the variable names contain such characters?

No explanation needed for '!'

Boom

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: A special visual effect code: The Matrix

#9 Post by Ed Dyreen » 30 Oct 2012 06:22

Boombox wrote:.

Code: Select all

set /a $ = !$lines! &for /l %%§ in (

              !$lines!, -1, 2

) do   set /a $ -= 1 &for %%? in (


One of many parts of this code that confuse me...

1: Are these characters used for any reason, other than, because you can? § $

2: And why do many of the variable names contain such characters?

No explanation needed for '!'

Boom
There are many characters with some very special characteristics for example:
'?' and '*' will be dropped in a simple for loop.
'~' cannot be used for string substitution.
'$' cannot be used to strip quotes from metavariables.
';' as a variable name cannot be displayed by using the set command, only by echo.
'!' cannot be used as variable name if delayed expansion is enabled.
etcetera..

[meta]variables [a-Z,0-9] on the other hand are considered "safe" but sometimes problems can arise.
Bug in function :Format
The reason I use them is to avoid these type of problems but also to keep the "normal" [meta]variables free.
Over time, I devellopped a preference for some characters like '?', '*', '~', '§' and '$'

Unless you fully understand their limitations, you should not use exotic characters :!:

Post Reply