USA Flag batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Rafhack
Posts: 19
Joined: 23 Feb 2014 15:02

USA Flag batch file

#1 Post by Rafhack » 27 May 2014 21:16

Code: Select all

@echo off
setlocal enabledelayedexpansion
mode con cols=140 lines=35

for /l %%a in (1,1,9) do (
   for /l %%b in (1,1,12) do (
      call:mostrarComCor "ÿÿÿ" "90"
      call:mostrarComCor "xÿ" "9F"
   )
   for /l %%b in (1,1,78) do (
      call:mostrarComCor "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,12) do (
      call:mostrarComCor "x" "9F"
      call:mostrarComCor "ÿÿÿÿ" "90"
   )
   for /l %%b in (1,1,78) do (
      call:mostrarComCor "ÿ" "F0"
   )
   echo/
)
for /l %%b in (1,1,8) do (
   for /l %%b in (1,1,138) do (
      call:mostrarComCor "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,138) do (
      call:mostrarComCor "ÿ" "F0"
   )
   echo/
)
pause>nul
exit/b
:mostrarComCor [txt][cor]
   for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
      set "DEL=%%a"
   )
   call :ColorText %~2 "%~1"
   exit/b
:ColorText
   <nul set /p ".=%DEL%" > "%~2"
   findstr /v /a:%1 /R "^$" "%~2" nul
   del "%~2" > nul 2>&1
   exit/b

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

Re: USA Flag batch file

#2 Post by foxidrive » 27 May 2014 21:42

How many stars are in the flag? :D

Nice little demo anyway.

ShadowThief
Expert
Posts: 909
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: USA Flag batch file

#3 Post by ShadowThief » 28 May 2014 01:11

216 stars and 34 stripes. I see the US has been fairly successful in its campaign to take over every country in the world.

miskox
Posts: 335
Joined: 28 Jun 2010 03:46

Re: USA Flag batch file

#4 Post by miskox » 28 May 2014 03:58

I get strange characters. Can you inlcude binarycharacters in a variable, something like viewtopic.php?p=33603#p33603

Einstein: the same problem is with your circles. Different codepages cause different characters so not all of us can see the correct output.

Thanks.
Saso

einstein1969
Expert
Posts: 763
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: USA Flag batch file

#5 Post by einstein1969 » 28 May 2014 09:24

miskox wrote:I get strange characters. Can you inlcude binarycharacters in a variable, something like viewtopic.php?p=33603#p33603

Einstein: the same problem is with your circles. Different codepages cause different characters so not all of us can see the correct output.

Thanks.
Saso


Thanks miskox, i have added the codepage. I don't know if it is enough for proper viewing. Can you test this change?

einstein1969

miskox
Posts: 335
Joined: 28 Jun 2010 03:46

Re: USA Flag batch file

#6 Post by miskox » 28 May 2014 13:44

In the forum I see these characters:

Image

And the result:

Image

Saso

einstein1969
Expert
Posts: 763
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: USA Flag batch file

#7 Post by einstein1969 » 28 May 2014 15:09

Hi miskox,

I see the same character but the output is right... :?

Image

I use copy and paste in notepad and save in ANSI.

Then i run in my default codepage (850).

Have you tried to change codepage before run?

einstein1969

miskox
Posts: 335
Joined: 28 Jun 2010 03:46

Re: USA Flag batch file

#8 Post by miskox » 28 May 2014 16:48

I added the CHCP 850 command but result is the same.

Can anyone make a HEX dump so I can try it that way?

Thanks.
Saso

einstein1969
Expert
Posts: 763
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: USA Flag batch file

#9 Post by einstein1969 » 28 May 2014 17:45

The char used is 0xFF, in my circle i use the classical 219.
This is the complete dump using the hexdump utility by dbenham.

Code: Select all

65 63 68 6F 20 6F 66 66 0D 0A 73 65 74 6C 6F 63 61 6C 20 65 6E 61 62 6C  echo off..setlocal enabl
65 64 65 6C 61 79 65 64 65 78 70 61 6E 73 69 6F 6E 0D 0A 6D 6F 64 65 20  edelayedexpansion..mode
63 6F 6E 20 63 6F 6C 73 3D 31 34 30 20 6C 69 6E 65 73 3D 33 35 0D 0A 0D  con cols=140 lines=35...
0A 66 6F 72 20 2F 6C 20 25 25 61 20 69 6E 20 28 31 2C 31 2C 39 29 20 64  .for /l %%a in (1,1,9) d
6F 20 28 0D 0A 20 20 20 66 6F 72 20 2F 6C 20 25 25 62 20 69 6E 20 28 31  o (..   for /l %%b in (1
2C 31 2C 31 32 29 20 64 6F 20 28 0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A  ,1,12) do (..      call:
6D 6F 73 74 72 61 72 43 6F 6D 43 6F 72 20 22 FF FF FF 22 20 22 39 30 22  mostrarComCor "..." "90"
0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A 6D 6F 73 74 72 61 72 43 6F 6D 43  ..      call:mostrarComC
6F 72 20 22 78 FF 22 20 22 39 46 22 0D 0A 20 20 20 29 0D 0A 20 20 20 66  or "x." "9F"..   )..   f
6F 72 20 2F 6C 20 25 25 62 20 69 6E 20 28 31 2C 31 2C 37 38 29 20 64 6F  or /l %%b in (1,1,78) do
20 28 0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A 6D 6F 73 74 72 61 72 43 6F   (..      call:mostrarCo
6D 43 6F 72 20 22 FF 22 20 22 43 30 22 0D 0A 20 20 20 29 0D 0A 20 20 20  mCor "." "C0"..   )..
65 63 68 6F 2F 0D 0A 20 20 20 66 6F 72 20 2F 6C 20 25 25 62 20 69 6E 20  echo/..   for /l %%b in
28 31 2C 31 2C 31 32 29 20 64 6F 20 28 0D 0A 20 20 20 20 20 20 63 61 6C  (1,1,12) do (..      cal
6C 3A 6D 6F 73 74 72 61 72 43 6F 6D 43 6F 72 20 22 78 22 20 22 39 46 22  l:mostrarComCor "x" "9F"
0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A 6D 6F 73 74 72 61 72 43 6F 6D 43  ..      call:mostrarComC
6F 72 20 22 FF FF FF FF 22 20 22 39 30 22 0D 0A 20 20 20 29 0D 0A 20 20  or "...." "90"..   )..
20 66 6F 72 20 2F 6C 20 25 25 62 20 69 6E 20 28 31 2C 31 2C 37 38 29 20   for /l %%b in (1,1,78)
64 6F 20 28 0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A 6D 6F 73 74 72 61 72  do (..      call:mostrar
43 6F 6D 43 6F 72 20 22 FF 22 20 22 46 30 22 0D 0A 20 20 20 29 0D 0A 20  ComCor "." "F0"..   )..
20 20 65 63 68 6F 2F 0D 0A 29 0D 0A 66 6F 72 20 2F 6C 20 25 25 62 20 69    echo/..)..for /l %%b i
6E 20 28 31 2C 31 2C 38 29 20 64 6F 20 28 0D 0A 20 20 20 66 6F 72 20 2F  n (1,1,8) do (..   for /
6C 20 25 25 62 20 69 6E 20 28 31 2C 31 2C 31 33 38 29 20 64 6F 20 28 0D  l %%b in (1,1,138) do (.
0A 20 20 20 20 20 20 63 61 6C 6C 3A 6D 6F 73 74 72 61 72 43 6F 6D 43 6F  .      call:mostrarComCo
72 20 22 FF 22 20 22 43 30 22 0D 0A 20 20 20 29 0D 0A 20 20 20 65 63 68  r "." "C0"..   )..   ech
6F 2F 0D 0A 20 20 20 66 6F 72 20 2F 6C 20 25 25 62 20 69 6E 20 28 31 2C  o/..   for /l %%b in (1,
31 2C 31 33 38 29 20 64 6F 20 28 0D 0A 20 20 20 20 20 20 63 61 6C 6C 3A  1,138) do (..      call:
6D 6F 73 74 72 61 72 43 6F 6D 43 6F 72 20 22 FF 22 20 22 46 30 22 0D 0A  mostrarComCor "." "F0"..
20 20 20 29 0D 0A 20 20 20 65 63 68 6F 2F 0D 0A 29 0D 0A 70 61 75 73 65     )..   echo/..)..pause
3E 6E 75 6C 0D 0A 65 78 69 74 2F 62 0D 0A 3A 6D 6F 73 74 72 61 72 43 6F  >nul..exit/b..:mostrarCo
6D 43 6F 72 20 5B 74 78 74 5D 5B 63 6F 72 5D 0D 0A 20 20 20 66 6F 72 20  mCor [txt][cor]..   for
2F 46 20 22 74 6F 6B 65 6E 73 3D 31 2C 32 20 64 65 6C 69 6D 73 3D 23 22  /F "tokens=1,2 delims=#"
20 25 25 61 20 69 6E 20 28 27 22 70 72 6F 6D 70 74 20 23 24 48 23 24 45   %%a in ('"prompt #$H#$E
23 20 26 20 65 63 68 6F 20 6F 6E 20 26 20 66 6F 72 20 25 25 62 20 69 6E  # & echo on & for %%b in
20 28 31 29 20 64 6F 20 72 65 6D 22 27 29 20 64 6F 20 28 0D 0A 20 20 20   (1) do rem"') do (..
20 20 20 73 65 74 20 22 44 45 4C 3D 25 25 61 22 0D 0A 20 20 20 29 0D 0A     set "DEL=%%a"..   )..
20 20 20 63 61 6C 6C 20 3A 43 6F 6C 6F 72 54 65 78 74 20 25 7E 32 20 22     call :ColorText %~2 "
25 7E 31 22 0D 0A 20 20 20 65 78 69 74 2F 62 0D 0A 3A 43 6F 6C 6F 72 54  %~1"..   exit/b..:ColorT
65 78 74 0D 0A 20 20 20 3C 6E 75 6C 20 73 65 74 20 2F 70 20 22 2E 3D 25  ext..   <nul set /p ".=%
44 45 4C 25 22 20 3E 20 22 25 7E 32 22 0D 0A 20 20 20 66 69 6E 64 73 74  DEL%" > "%~2"..   findst
72 20 2F 76 20 2F 61 3A 25 31 20 2F 52 20 22 5E 24 22 20 22 25 7E 32 22  r /v /a:%1 /R "^$" "%~2"
20 6E 75 6C 0D 0A 20 20 20 64 65 6C 20 22 25 7E 32 22 20 3E 20 6E 75 6C   nul..   del "%~2" > nul
20 32 3E 26 31 0D 0A 20 20 20 65 78 69 74 2F 62                           2>&1..   exit/b


einstein1969

ShadowThief
Expert
Posts: 909
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: USA Flag batch file

#10 Post by ShadowThief » 29 May 2014 06:35

miskox wrote:I added the CHCP 850 command but result is the same.

Can anyone make a HEX dump so I can try it that way?

Thanks.
Saso

Why 850 and not 437 or 1252?

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

Re: USA Flag batch file

#11 Post by foxidrive » 29 May 2014 06:56

Mine is 850 and it displays ok. The editor being used to paste the text is another variable.

Try notepad.

miskox
Posts: 335
Joined: 28 Jun 2010 03:46

Re: USA Flag batch file

#12 Post by miskox » 29 May 2014 12:37

No difference. I use XP PRO 32bit. Can anyone with XP test this if it works?

Saso

Squashman
Expert
Posts: 4113
Joined: 23 Dec 2011 13:59

Re: USA Flag batch file

#13 Post by Squashman » 29 May 2014 16:18

miskox wrote: Can anyone with XP test this if it works?

Saso

Does it really matter? The flag is far from even coming close to being an accurate representation of the US Flag. Way to many stars and way too many stripes.

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

Re: USA Flag batch file

#14 Post by foxidrive » 29 May 2014 18:58

This speeds the code up a bit FWIW

Code: Select all

@echo off
setlocal enabledelayedexpansion
mode con cols=140 lines=35

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


for /l %%a in (1,1,9) do (
   for /l %%b in (1,1,12) do (
      call:ColorText "ÿÿÿ" "90"
      call:ColorText "xÿ" "9F"
   )
   for /l %%b in (1,1,78) do (
      call:ColorText "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,12) do (
      call:ColorText "x" "9F"
      call:ColorText "ÿÿÿÿ" "90"
   )
   for /l %%b in (1,1,78) do (
      call:ColorText "ÿ" "F0"
   )
   echo/
)
for /l %%b in (1,1,8) do (
   for /l %%b in (1,1,138) do (
      call:ColorText "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,138) do (
      call:ColorText "ÿ" "F0"
   )
   echo/
)
pause>nul
exit/b
:ColorText
   <nul set /p ".=%DEL%" > "%~1"
   findstr /v /a:%2 /R "^$" "%~1" nul
   del "%~1" > nul 2>&1
   exit/b

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

Re: USA Flag batch file

#15 Post by foxidrive » 29 May 2014 19:21

This is a little more like the actual flag - I'm not sure that it can be made totally accurate...

Code: Select all

@echo off
setlocal enabledelayedexpansion
mode con cols=80 lines=25

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


for /l %%a in (1,1,5) do (
   for /l %%b in (1,1,6) do (
      call:ColorText "ÿÿÿ" "90"
      call:ColorText "xÿ" "9F"
   )
   for /l %%b in (1,1,30) do (
      call:ColorText "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,6) do (
      call:ColorText "x" "9F"
      call:ColorText "ÿÿÿÿ" "90"
   )
   for /l %%b in (1,1,30) do (
      call:ColorText "ÿ" "F0"
   )
   echo/
)
for /l %%b in (1,1,3) do (
   for /l %%b in (1,1,60) do (
      call:ColorText "ÿ" "C0"
   )
   echo/
   for /l %%b in (1,1,60) do (
      call:ColorText "ÿ" "F0"
   )
   echo/
)
pause>nul
exit/b
:ColorText
   <nul set /p ".=%DEL%" > "%~1"
   findstr /v /a:%2 /R "^$" "%~1" nul
   del "%~1" > nul 2>&1
   exit/b

Post Reply