USA Flag batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

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

Re: USA Flag batch file

#16 Post by Squashman » 29 May 2014 19:46

I wouldn't expect exact perfection but at least get it close. heck I would even accept the 80/20 rule.

Liviu
Expert
Posts: 470
Joined: 13 Jan 2012 21:24

Re: USA Flag batch file

#17 Post by Liviu » 29 May 2014 20:59

miskox wrote:I use XP PRO 32bit. Can anyone with XP test this if it works?

Confirmed here that it doesn't work in XP. Problem seems to be with the 'findstr' screen output. It probably has to do with Dave's note "most control characters and many extended ASCII characters display as dots on XP" at http://stackoverflow.com/questions/8844868/what-are-the-undocumented-features-and-limitations-of-the-windows-findstr-comman which causes ". ." to be displayed in XP for the backspace-space-backspace sequence.

Liviu

dbenham
Expert
Posts: 2288
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: USA Flag batch file

#18 Post by dbenham » 29 May 2014 22:18

I don't understand why prior attempts make so many calls to :ColorText. Excessive calls slow the script way down. There is no need to make multiple calls when the color doesn't change :roll:

Here is a version using jeb's version of :color at http://stackoverflow.com/a/5344911/1012053. This at least has the correct number of stars and stripes, but the proportions are all wrong.

Code: Select all

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

rem Prepare a file "X" with only one dot
<nul > X set /p ".=."

set   "star1=X   X   X   X   X   X"
set   "star2=  X   X   X   X   X  "
set "stripe1=                     "
set "stripe2=                                          "

call :Color 9F "%star1%" & call :Color C0 "%stripe1%" & echo(
call :Color 9F "%star2%" & call :Color F0 "%stripe1%" & echo(
call :Color 9F "%star1%" & call :Color C0 "%stripe1%" & echo(
call :Color 9F "%star2%" & call :Color F0 "%stripe1%" & echo(
call :Color 9F "%star1%" & call :Color C0 "%stripe1%" & echo(
call :Color 9F "%star2%" & call :Color F0 "%stripe1%" & echo(
call :Color 9F "%star1%" & call :Color C0 "%stripe1%" & echo(
call :Color 9F "%star2%" & call :Color F0 "%stripe1%" & echo(
call :Color 9F "%star1%" & call :Color C0 "%stripe1%" & echo(
call :Color F0 "%stripe2%" & echo(
call :Color C0 "%stripe2%" & echo(
call :Color F0 "%stripe2%" & echo(
call :Color C0 "%stripe2%" & echo(
exit /b

:Color
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
exit /b


Dave Benham

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

Re: USA Flag batch file

#19 Post by miskox » 30 May 2014 02:13

Squashman wrote: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.


It's not the US flag it is the fact that I have problems with other command procedures (.cmds) aswell. And it looks like this is the reason.

@Liviu: this is the reason, yes. Good memory to find it.

@dave: your version works on XP.

Thanks.
Saso

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

Re: USA Flag batch file

#20 Post by Squashman » 30 May 2014 09:51

dbenham wrote:This at least has the correct number of stars and stripes, but the proportions are all wrong.

I think you are missing a row of white and a row of red. :lol:

But hey it runs a million times faster and is pretty much a million times more accurate. :D

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

Re: USA Flag batch file

#21 Post by foxidrive » 30 May 2014 10:15

Dave's is quick alright!

It does occur to me that some part of the flag drawing could be the creation of the image - and a little bit of a delay when drawing might add to the effect.

dbenham
Expert
Posts: 2288
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: USA Flag batch file

#22 Post by dbenham » 30 May 2014 10:56

Squashman wrote:
dbenham wrote:This at least has the correct number of stars and stripes, but the proportions are all wrong.

I think you are missing a row of white and a row of red. :lol:

But hey it runs a million times faster and is pretty much a million times more accurate. :D

No, I'm not missing stripes. There are 13, just like there are supposed to be. But the proportions are all wrong.

The problem is the real flag has 7 stripes for 9 rows of stars, with 6 additional stripes below.

My "solution" has 1 stripe for each row of stars (total of 9), leaving only 4 stripes below.

To get a correct solution would require 117 lines of text. (7 lines of text for each star row, and 9 lines of text for each stripe)


Dave Benham

dbenham
Expert
Posts: 2288
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: USA Flag batch file

#23 Post by dbenham » 30 May 2014 12:45

OK Mr Squashman - Here is a realistic looking US Flag. :wink:

Make sure you set up your console to have a buffer size of at least width=275 and height=120. I also recommend setting the font size to 4x6. Once configured, then you are ready to run USFLAG.BAT

Code: Select all

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

rem Prepare a file "X" with only one dot
<nul > X set /p ".=."

set  "star0=    @                 @                 @                 @                 @                 @    "
set  "star1=    @                 @                 @                 @                 @                 @    "
set  "star2=   @@@               @@@               @@@               @@@               @@@               @@@   "
set  "star3=@@@@@@@@@         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@"
set  "star4=  @@@@@             @@@@@             @@@@@             @@@@@             @@@@@             @@@@@  "
set  "star5=   @@@               @@@               @@@               @@@               @@@               @@@   "
set  "star6=  @   @             @   @             @   @             @   @             @   @             @   @  "
set  "star7=             @                 @                 @                 @                 @             "
set  "star8=             @                 @                 @                 @                 @             "
set  "star9=            @@@               @@@               @@@               @@@               @@@            "
set "star10=         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@         @@@@@@@@@         "
set "star11=           @@@@@             @@@@@             @@@@@             @@@@@             @@@@@           "
set "star12=            @@@               @@@               @@@               @@@               @@@            "
set "star13=           @   @             @   @             @   @             @   @             @   @           "
set "stripe1="
for /l %%N in (1 1 168) do set "stripe1=!stripe1! "
set "stripe2=!stripe1:~0,99!"

cls
for /l %%N in (0 1 62) do (
  set /a "starN=%%N%%14, stripeN=(%%N/9)%%2"
  for %%n in (!starN!) do call :color 9F "!star%%n!"
  if "!stripeN!" equ "0" (call :color C0 "%stripe1%") else call :color F0 "%stripe1%"
  echo(
)
for %%C in (F0 C0 F0 C0 F0 C0) do for /l %%N in (1 1 9) do (
  call :color %%C "%stripe1%"
  call :color %%C "%stripe2%"
  echo(
)
exit /b

:color
set "param=^%~2" !
set "param=!param:"=\"!"
findstr /p /A:%1 "." "!param!\..\X" nul
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
exit /b


Dave Benham

penpen
Expert
Posts: 1725
Joined: 23 Jun 2013 06:15
Location: Germany

Re: USA Flag batch file

#24 Post by penpen » 06 Jun 2014 08:49

It seems that the smallest possible flag could not be done using "findstr", as the '▄' character seems not to be supported by "findstr" ... .
(At least i've found no solution to display that character using "findstr" on my win xp home 32 bit.)

So if you use for example "setColor.exe" compiled using "setColor.cs":

Code: Select all

using System;

class Example {

   public static void Main (string [] args) {
      if (args.Length == 0) {
         Console.WriteLine ("Usage: setColor [color text]*");
         Console.WriteLine ("color text   it writes the text in the specified color to the console");
         Console.WriteLine ("color        hex value defining background/foreground color (high/low nibble) (2 hex digits)");
         Console.WriteLine ("");
         Console.WriteLine ("If you want to use partial defaults, just use a '-'/'+' (background/foreground) instead of the hex value");

      } else {
         string H = "0123456789ABCDEF";
         int B = (int) Console.BackgroundColor;
         int F = (int) Console.ForegroundColor;
         int c;

         for (int i = 0; i < args.Length; i+=2) {
            try {
               c = int.Parse (args [i].Replace('+', H [F]).Replace('-', H [B]), System.Globalization.NumberStyles.HexNumber);
               Console.BackgroundColor = (ConsoleColor) ((c >> 4) & 0xF);
               Console.ForegroundColor = (ConsoleColor) (c & 0xF);
            } catch {
               Console.BackgroundColor = (ConsoleColor) B;
               Console.ForegroundColor = (ConsoleColor) F;
            }

            Console.Write (args [i + 1]);
         }

         Console.ResetColor();
      }
   }
}
Then you could create a us flag using "flag.bat":

Code: Select all

@echo off
setlocal
if not exist "setColor.exe" call :compileSetColor
set "cp=850"
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%a"
chcp 850 > nul


set   "star0=                         "
set   "star1=  *   *   *   *   *   *  "
set   "star2=    *   *   *   *   *    "
set   "star3=ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ"
set "stripe1=                                     "
set "stripe2=                                                              "
set "stripe3=ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ"
set "stripe4=ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ"
set "stripe5=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"
set "stripe6=ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"

setColor 1F "%star0%" CF "%stripe1%" & echo(
setColor 1F "%star1%" CF "%stripe3%" & echo(
setColor 1F "%star2%" CF "%stripe5%" & echo(
setColor 1F "%star1%" CF "%stripe1%" & echo(
setColor 1F "%star2%" CF "%stripe3%" & echo(
setColor 1F "%star1%" CF "%stripe5%" & echo(
setColor 1F "%star2%" CF "%stripe1%" & echo(
setColor 1F "%star1%" CF "%stripe3%" & echo(
setColor 1F "%star2%" CF "%stripe5%" & echo(
setColor 1F "%star1%" CF "%stripe1%" & echo(
setColor 1F "%star3%" CF "%stripe3%" & echo(
setColor CF "%stripe6%" & echo(
setColor CF "%stripe2%" & echo(
setColor CF "%stripe4%" & echo(
setColor CF "%stripe6%" & echo(
setColor CF "%stripe2%" & echo(
setColor CF "%stripe4%" & echo(
setColor CF "%stripe6%" & echo(
setColor CF "%stripe2%" & echo(
setColor C- "%stripe4%" & echo(

chcp %cp% > nul
endlocal
exit /B


:compileSetColor
   setlocal
   set "csc="

   pushd "%SystemRoot%\Microsoft.NET\Framework"
   for /f "tokens=* delims=" %%i in ('dir /b /o:n "v*"') do (
      dir /a-d /b "%%~fi\csc.exe" >nul 2>&1 && set "csc="%%~fi\csc.exe""
   )
   popd

   if defined csc (
rem      echo most recent C#.NET compiler located in:
rem      echo %csc%.
   ) else (
      echo C#.NET compiler not found.
      goto :eof
   )

   %csc% /nologo /optimize /warnaserror /nowin32manifest /debug- /target:exe /out:"setColor.exe" "setColor.cs"
   endlocal
   exit /B

penpen

Aacini
Expert
Posts: 1617
Joined: 06 Dec 2011 22:15
Location: México City, México

Re: USA Flag batch file

#25 Post by Aacini » 06 Jun 2014 16:24

I don't think that the purpose of this thread be to draw the USA flag using an external .exe program; otherwise, you may do that in an easier way using my ColorShow.exe auxiliary program that does not require any compiler: just download it from this site. Look for program # 12-ColorShow.exe.

Code: Select all

@echo off
setlocal

set "cp=850"
for /F "tokens=2 delims=:." %%a in ('chcp') do set "cp=%%a"
chcp 850 > nul

set "star1=  *   *   *   *   *   *  "
set "star2=    *   *   *   *   *    "

ColorShow /1F  32*25    /CF  32*37 13 10
ColorShow /1F "%star1%" /CF 220*37 13 10  /1F "%star2%" /CF 219*37 13 10  /1F "%star1%" /CF  32*37 13 10
ColorShow /1F "%star2%" /CF 220*37 13 10  /1F "%star1%" /CF 219*37 13 10  /1F "%star2%" /CF  32*37 13 10
ColorShow /1F "%star1%" /CF 220*37 13 10  /1F "%star2%" /CF 219*37 13 10  /1F "%star1%" /CF  32*37 13 10
ColorShow /1F  220*25   /CF 220*37 13 10
ColorShow /CF  219*62 13 10  32*62 13 10      220*62 13 10  219*62 13 10  32*62 13 10  220*62 13 10 
ColorShow /CF  219*62 13 10  32*62 13 10  /C0 220*62 13 10 

chcp %cp% > nul


Image

Antonio

penpen
Expert
Posts: 1725
Joined: 23 Jun 2013 06:15
Location: Germany

Re: USA Flag batch file

#26 Post by penpen » 07 Jun 2014 02:21

I've primary added the source to avoid questions like why is the '▄' character needed to draw the flag of the USA.

I assume i would have used your ColorShow.exe auxiliary program, if i would have noticed it earlier (less work for me),
but i don't think that it was much easier to use it, instead of using my source above.
You would have to download the sources ("USA Flag.bat", "ColorShow.exe.hex"), and your compiler files ("HexToBin.bat", "HexToBin.vbs").
Beside, your batch program "HexToBin.bat" is a (very simple) compiler, too:
It translates expressions of the form (('0'-'9'|'a-f'|'A'-'F')^2|'['('0'-'9')+']'|('\r'?'\n')* to (0x00-0xFF)*.

I think the "csc.exe" (c# compiler) is as external as "findstr.exe" and should be preinstalled on actual windows systems by default (winxp is outdated).
You shouldn't have to install it (except if your admin has thrown it away, or has created a install CD/DVD without .NET framework):
You only have to save the above sources ("setColor.cs" "flag.bat") and just run the batch file.

penpen

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

Re: USA Flag batch file

#27 Post by einstein1969 » 09 Jun 2014 11:08

penpen wrote:It seems that the smallest possible flag could not be done using "findstr", as the '▄' character seems not to be supported by "findstr" ... .
(At least i've found no solution to display that character using "findstr" on my win xp home 32 bit.)

Hi penpen!

Have you tried the /F option of findstr?

einstein1969

penpen
Expert
Posts: 1725
Joined: 23 Jun 2013 06:15
Location: Germany

Re: USA Flag batch file

#28 Post by penpen » 09 Jun 2014 12:57

My windows xp shows a '=' instead of '▄' (i don't know why, or how to work around this).
(And windows 7 shows graphical errors on the right side of the blue star field... .)

penpen

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

Re: USA Flag batch file

#29 Post by einstein1969 » 09 Jun 2014 14:32

penpen wrote:My windows xp shows a '=' instead of '▄' (i don't know why, or how to work around this).
(And windows 7 shows graphical errors on the right side of the blue star field... .)

penpen


:(

Post Reply