Page 1 of 1

Another "MODE" trick demo

Posted: 05 Sep 2014 10:35
by einstein1969
Hi, I have this code for demo the "MODE" trick.

This is old code. If anyone needs...

There is no antiflicker but in the forum there'are suggestion for antiflicker if necessary.
And i think that is necessary to "FLUSH" the input buffer. See in the forum the discussion of "arrow keys"

Code: Select all

@echo off & setlocal EnableDelayedExpansion & Goto :Init_system

:Main

cls & mode %cols%,%lines%

echo(&Echo Center the dos command windows and&pause

call :wait 1000

cls & mode 15,20 & color 08

set /a tmp_cols=cols, tmp_lines=lines, Cols=15, lines=20, pos=0

For %%c in (4 c e a 2 1 5 8 7 f 7 8   8 7 f b 3 9 1) do (
  call :blinking_line !pos! %%c %cols%
  set /a pos+=1
)

set cols=%tmp_cols%

mode %cols%,%lines%

call :wait 1000

set /a lines=tmp_lines, pos+=23

mode %cols%,%lines%

call :wait 1000

rem avvio il processo che aspetta un tasto
start "" /B xcopy /w "%~f0" "%~f0" >>"%temp%\wait.tmp" 2>nul

for /L %%n in (1,1,23) do (
  call :wait 8
  set /a pos-=1
  call :press !pos! %%n
)

set /a pos-=1, cle=1
:repeat
(
  title !time!
  call :press !pos! 13
  if !pos! geq 12 (
   if !pos! gtr 12 set /a pos-=1
   set cl=1
        For %%c in (1 9 3 b f 7 8) do (
      if !cl! equ !cle! call :ColorText_bg_BS %%c %cols%
      set /a cl+=1
   )
   set /a cle+=1
   call :wait 7
  ) else call :wait_colorize 500
2>nul (>>"%temp%\wait.tmp" call )||goto :repeat
)

goto :End_Main

rem fare un echo con una sola linea! lasciare le variabili str nell'echo. Si risparmia rispetto al set/p.
:press pos nlines
(
  set ne=%2
  mode %cols%,%lines%
  For /L %%l in (1,1,%1) do echo(
  if !ne! equ 13 (<nul set /p "=!s1!!str1:~0,72!!s2!!str2:~0,72!!s3!!str3:~0,72!!s4!!str4:~0,72!!s5!"
  ) else (
     for %%m in (
      "Û²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²Û"
      "Û²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±²Û"
      "Û²±°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°±²Û"
      "Û²±°                                                                      °±²Û"
      "²±°                                                                        °±²"
      "±° !str1:~0,72! °±"
      "°  !str2:~0,72!  °"
      "±° !str3:~0,72! °±"
      "²±°!str4:~0,72!°±²"
      "Û²±°                                                                      °±²Û"
      "Û²±°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°±²Û"
      "Û²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±²Û"
      "Û²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²Û"
   ) do (
      if !ne! gtr 0 <nul set /p "=%%~m"
      set /a ne-=1
   )
  )

  set str1=!str1:~1!!str1:~0,1!
  set str2=!str2:~1!!str2:~0,1!
  set str3=!str3:~1!!str3:~0,1!
  set str4=!str4:~1!!str4:~0,1!

goto :eof
)

:blinking_line pos finalcolor len [/n]
(
  set t0=!time!
  For %%. in (8 7 f 7 7 8 8 8 8 %2) do (
    mode %cols%,%lines%
    For /L %%l in (1,1,%1) do echo(
    call :ColorText_bg_BS %%. %3 %4
    for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
    set /a a=5-a
    if !a! gtr 0 call :wait !a!
    set t0=!time!
  )
goto :eof
)

rem utile per riscrivere una linea senza lasciare lo spazio vuoto. Usa BS al posto di DEL.
rem Per len <=1 non funziona.
rem Non usare se si desidera stampare a destra perche' il BS tornato indietro fa sovrascrivere l'ultimo colore stampato


:ColorText_bg_BS bg_color len [/n]
(   
  set /a "len=%2-1"
  if !len! geq 1 for %%. in (!len!) do  findstr /v /a:%1%1 /R "^$" "!str_findstr:~0,%%.!" nul
  if /i "%~3"=="/n" echo(
goto :eof
)

:wait_colorize

  rem avvia ping
  start "" /B ping 192.0.2.0 -n 1 -w 500 >>"%temp%\wait_colorize.tmp" 2>nul
 
  For /L %%l in (1,1,6) do echo(
:repeat_colorize

  call :ColorText_bg_BS 4 76
  <nul set /p "=!BS!!CR!"

2>nul (>>"%temp%\wait_colorize.tmp" call )||goto :repeat_colorize

goto :eof


:wait time_cs time
(
  if %1 gtr 100 (ping 192.0.2.0 -n 1 -w %1 >nul & goto :eof)
  set t0=!time!
:wait_loop
  for /F "tokens=1-8 delims=:.," %%a in ("!t0: =0!:!time: =0!") do set /a "a=(((1%%e-1%%a)*60)+1%%f-1%%b)*6000+1%%g%%h-1%%c%%d, a+=(a>>31) & 8640000"
  if !a! lss %1 goto :wait_loop
goto :eof
)

:init_system

rem passa alla directory temporanea
pushd "%temp%"

for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"

rem genero il DEL
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)

:: Define BS to contain a backspace
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

rem larghezza schermo
set /a cols=78, lines=43

rem preparo una stringa lunga %cols% caratteri

set "str_findstr="
For /L %%c in (1,1,%cols%) do set "str_findstr=!str_findstr!L"

rem creo tutte le possibili lunghezze
For /L %%l in (1,1,%cols%) do <nul set /p .=%BS%> "!str_findstr:~0,%%l!"

set "str1= ____  ____  ____  ____  ____      __   __ _  _  _     __ _  ____  _  _           "
set "str2=(  _ \(  _ \(  __)/ ___)/ ___)    / _\ (  ( \( \/ )   (  / )(  __)( \/ )          "
set "str3= ) __/ )   / ) _) \___ \\___ \   /    \/    / )  /     )  (  ) _)  )  /           "
set "str4=(__)  (__\_)(____)(____/(____/   \_/\_/\_)__)(__/     (__\_)(____)(__/            "

set "s1="
for %%m in (
   "Û²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²Û"
   "Û²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±²Û"
   "Û²±°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°±²Û"
   "Û²±°                                                                      °±²Û"
   "²±°                           By Einstein1969                              °±²"
   "±° ") do set s1=!s1!%%~m
set "s2="
for %%m in (                              " °±"
   "°  ") do set s2=!s2!%%~m
set "s3="
for %%m in (                              "  °"
   "±° ") do set s3=!s3!%%~m
set "s4="
for %%m in (                              " °±"
   "²±°") do set s4=!s4!%%~m
set "s5="
for %%m in (                              "°±²"
   "Û²±°                                                                      °±²Û"
   "Û²±°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°±²Û"
   "Û²±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±²Û"
   "Û²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²Û") do set s5=!s5!%%~m

goto :Main

:End_Main
  popd
Goto :eof


einstein1969

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 10:52
by Squashman
I am not sure what your code is doing but it looked horrible when I ran it. Looked like the screen kept closing and resizing. It was like watching a strobe light.

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 11:03
by einstein1969
This code show how keep colors and animation at the same time using native dos commands.

This use a "mode" command tricks.

The resize "demo" show how replicate colors in the screen with a single instruction.

without using mode this is not possible!!

einstein1969

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 11:08
by foxidrive
Squashman wrote:I am not sure what your code is doing but it looked horrible when I ran it. Looked like the screen kept closing and resizing. It was like watching a strobe light.


It works ok here - may need a faster CPU or GPU??

It creates a smaller window and horizontal coloured bars fill it up with a highlighted bar effect
The the window triples in width and then increases in height and a scrolling animation appears "press any key"

It's pretty effective.

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 11:17
by Squashman
Well I always thought einstein ran with a single core. I am running a dual core with an Nvidia gpu.

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 12:53
by foxidrive
Squashman wrote:Well I always thought einstein ran with a single core. I am running a dual core with an Nvidia gpu.


I think you are right.

See it here under Win 7: http://tinypic.com/r/ei8f2e/8

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 13:48
by Squashman
What did you use to record that?

Re: Another "MODE" trick demo

Posted: 05 Sep 2014 22:47
by foxidrive
Squashman wrote:What did you use to record that?


FastStone Capture. It's my new replacement for Snagit.

Re: Another "MODE" trick demo

Posted: 08 Sep 2014 14:01
by pieh-ejdsch
@ Einstein
cmd buffer use maximal

Code: Select all

mode 80,9999

Than you can use mode without minimize lines
Into the animated field from left to the right side write full colored signs.
Now use mode, go to the line for animation and write the letters only without the right wall (with linefeed).

Why do you not use your "ping Heartbeat" for a simplier and small CPU usage?

Phil

Re: Another "MODE" trick demo

Posted: 09 Sep 2014 02:04
by tcpman
nice work!

Re: Another "MODE" trick demo

Posted: 09 Sep 2014 02:50
by einstein1969
pieh-ejdsch wrote:@ Einstein
cmd buffer use maximal

Code: Select all

mode 80,9999

Than you can use mode without minimize lines
Into the animated field from left to the right side write full colored signs.
Now use mode, go to the line for animation and write the letters only without the right wall (with linefeed).

Why do you not use your "ping Heartbeat" for a simplier and small CPU usage?

Phil


Hi Phil,

Thanks for your response.

I did not understand everything you have written.
I am, however, agree with you on the fact that the heartbeat is considerably reduced the use of cpu. This code I wrote when the "ping heartbeat" was not born yet :)
I am struggling to write code because my mind has aged a lot in the last year. Also my pc is dying ... I hope that some of you carry forward my studies until I return to the regime.

F.P.

Re: Another "MODE" trick demo

Posted: 09 Sep 2014 13:49
by carlos
einstein the performance can be improved using this ?:

for example for multiply n by 60:

Code: Select all

set /a "n=2"


instead of this :

Code: Select all

set /a "res=n*60"


use:

Code: Select all

set /a "(n<<6)-(n<<2)"


or multiply by 6000:
instead of this :

Code: Select all

set /a "res=n*6000"


use:

Code: Select all

set /a "(n<<12)+(n<<11)-(n<<7)-(n<<4)"

Re: Another "MODE" trick demo

Posted: 10 Sep 2014 09:40
by einstein1969
carlos wrote:einstein the performance can be improved using this ?:

for example for multiply n by 60:

Code: Select all

set /a "n=2"


instead of this :

Code: Select all

set /a "res=n*60"


use:

Code: Select all

set /a "(n<<6)-(n<<2)"


or multiply by 6000:
instead of this :

Code: Select all

set /a "res=n*6000"


use:

Code: Select all

set /a "(n<<12)+(n<<11)-(n<<7)-(n<<4)"



Hi Carlos,

i have measured on my windows seven monocore and the time for execute:

Code: Select all

set /a "res=n*60"

is 34-35 microsec

the time for execute:

Code: Select all

set /a "res=(n<<6)-(n<<2)"

is 38-39 microsec

this with empty environment, no running applications and let n=2

einstein1969