Batch Script to make ColorShow Checkerboards

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Batch Script to make ColorShow Checkerboards

#1 Post by Jer » 27 Oct 2016 00:38

revised 10/29/2016 - able to display larger boards by splitting input to colorshow.exe if needed. added more examples.
code revised 10/27/2016 - added plus symbol to /b switch for 2-column wide border verticals

This batch script should be good for a few minutes of amazement.
If there is not yet a checkboard generator, here it is.
If there are any glitches, I'll fix it.

A day of diversion while plodding along with release 2 of mega-FrameTool.
Aacini's colorshow.exe made it all possible.
Enjoy :D

cboard.bat:

Code: Select all

@Echo Off

setlocal EnableDelayedExpansion
@:
@: Batch script builds a string of parameters from batch arguments
@: to display checkered and patterned boards with ColorShow.exe.
@:
@: The following codes with their parameters are entered from the command-line
@: and must be preceded by a forward slash:
@:
@: a = across # of squares, min=2, max=30, default=2:  /a5
@: d = down # of squares, min=1, max=30, default=2:  /d4
@: w = width of square, max=16, default=1:  /w6
@: h = height of square, # of lines, max=16, default=1: /h3
@: c = color of alternate squares background, default=78:  /ce1  (yellow square, blue square, ...)
@: c..:.. = alternate squares b/f colors if filler ascii code(s) entered:  /ce4:1b 178:177
@: b = border b/f colors, default=87:  /b08  (/b00=black border)
@: b.+ = border verticals 2 columns wide with solid color:  /be+
@: bxx = no border:  /bxx
@: i = indent # columns, max=60, default=0:  /i3
@:
@: No forward slash for this optional entry:
@: ###:### = ascii codes in range 1-255 as fillers (default=32:32):  177:178
@:
@: notes:
@: command-line entries are accepted in any order.
@:
@: Entries exceeding the maximum will be adjusted to the maximum allowed.
@:
@: When 2 ascii codes are entered as fillers, 2 sets of unique color codes are needed
@: to produce a checkered effect: /c1f:4b 178:177
@:
@: Enter ? to view this information.
@:
::  examples:
::: /a2 /d1 /w20 /h8 /ce4 /b0e /i1
::: /a8 /d8 /w6 /h2 /cf0 /b07 /i6
::: /a4 /d4 /w6 /h2 /c2a /b67 /i1
::: /h6 /w12 /a3 /d3 /c1b /b08 /i4
::: /h5 /w10 /a5 /d4 /c2c:4e 221:178 /b47 /i2
::: /a4 /d4 /w9 /h4 /c26:f1 /i1 /b01 176:177
::: /a7 /d5 /w9 /h2 /c5b:8c /b8c 176:178
::: /a17 /d14 /w3 /h1 /ca4:a4 /b2a 179:177 /i6
::: /a20 /d8 /w1 /h1 /ce0:1f 15:197 /b2+ /i20
::: /a3 /d3 /w5 /h2 /cf1:0c 178:176 /b00 /i1
::: /a12 /d10 /w4 /h2 /c36:1d /bc+ /i1 219
::: /a8 /d10 /w9 /h2 /cf8:e2 /bxx /i2 219:219
::: /a20 /d16 /w3 /h1 /c6b:20 /b67 179:223 /i2
::: /a7 /d5 /w10 /h4 /cb0:23 /b2+ 206:254 /i4
::: /a3 /d3 /w11 /h5 /c4c:af /i1 /b22 220:220
::: /a7 /d4 /w5 /h2 /cbf:51 /i1 /bcc 177:178
::: /a15 /d10 /w5 /h2 /cc0 /bab /i2
::: /a9 /d9 /w5 /h2 /c28:ac /i1 /b00 176:178
::: /a22 /d22 /w2 /h1 /c5e /b2e /i2
::: /a2 /d2 /w7 /h3 /c04:e2 /b22 178
::: /a3 /d2 /w16 /h6 /c4b:76 179:176 /b2 /i4
::: /a4 /d4 /cce:4f 196:197 /b11 /i8
::: /a5 /d2 /w16 /h1 /b66 /cfc:42 /i1 254:223
::: /a19 /d16 /w2 /h1 /c5b:03 197:222 /bxx /i8
::: /a3 /d3 /w7 /h3 /cce /b1d /i1 197:196
::: /a3 /d3 /w9 /h4 /c0e:e1 /i1 /bee 176:197
::: /a25 /d20 /w3 /h1 /cec:b8 /b8+ /i2 221:254
::: /a6 /d6 /w8 /h3 /c60 /b2+ /i3
::: /a10 /d5 /w6 /h2 /cc0:f0 /b00 /i3 178:219
::: /a16 /d14 /w3 /h1 /c14:7f /bxx /i2 219:223
::: /a10 /d10 /w5 /h2 /c38:ea /i1 /b00 176:178
::
If not EXIST ColorShow.exe Echo The file colorshow.exe was not found in this folder.  Exiting.& GoTo:eof

Set "str=%*" & Set "params="
If "%str%"=="" (
   Set "prg=%~n0"
   colorshow /0b " This batch script generates checkerd and patterened boards.  Enter " /0e "!prg! ?" /0b " for details." 13 10
   Set "str=/i30 32:32")
If "%str%"=="?" Call :showSamples & GoTo:eof

If not "%str%"=="!str:/=!" Set "str=/i0 %str%"
Call :getParams "%str%" retVars

For /F "tokens=1-11 delims=," %%a In ("%retVars%") Do (
   Set "across=%%a" & Set "down=%%b"
   Set "sqWidth=%%c" & Set "sqHeight=%%d"
   Set "c1=%%e" & Set "c2=%%f"
   Set "bdrColors=%%g" & Set "indent=%%h"
   Set "ascii1=%%i" & Set "ascii2=%%j" & Set "vertWide=%%k")

If "%ascii1%%ascii2%"=="3232" (
   rem solid colors will be displayed
   Set "color1=%c2:~1,1%" & Set "color2=%c2:~0,1%"
   Set "color1=!color1!!color1!" & Set "color2=!color2!!color2!"
) Else (Set "color1=%c1%" & Set "color2=%c2%")

If "%vertWide%"=="TRUE" (
   Set "bdrColors=%bdrColors:~0,1%%bdrColors:~0,1%"
   Set "vertChar=32*2"
) Else (Set "vertChar=179")

If %indent% gtr 0 Set "indentStr=/07 32*%indent%"

If not "%bdrColors%"=="XX" (
   Set "VTL=%indentStr% /%bdrColors% %vertChar%"
   Set "VTR=/%bdrColors% %vertChar%"
   If "%vertWide%"=="TRUE" (
      Set "UL=32*2" & Set "UR=32*2" & Set "HZ=32"
   ) Else (Set "UL=218" & Set "UR=191" & Set "HZ=196")
   If "%vertWide%"=="TRUE" (
      Set "LL=32*2" & Set "LR=32*2"
   ) Else (Set "LL=192" & Set "LR=217")
   Set /A "bdrHZLen=%across%*%sqWidth%"
   Set "params=13 10 %indentStr% /%bdrColors% !UL! !HZ!*!bdrHZLen! !UR! 13 10"
) Else (
   Set "params=13 10"
   If %indent% gtr 0 Set "VTL=%indentStr%")

rem build the string of parameters for colorshow.exe that defines the board
Set "length=0"
For /L %%r In (1,1,%down%) Do (
   Set /A "n=%%r%%2"
   If !n! equ 0 (
      Set "c1=%color1%" & Set "c2=%color2%"
   ) Else (
      Set "c1=%color2%" & Set "c2=%color1%")

   For /L %%s In (1,1,%sqHeight%) Do (
      Set "z=0"
      Set "params=!params! %VTL%"
      For /L %%t In (1,1,%across%) Do (
         If !z! lss %across% Set "params=!params!/!c1! %ascii1%*%sqWidth%"
         Set /A "z+=2"
         If !z! leq %across% Set "params=!params!/!c2! %ascii2%*%sqWidth%"
      )
      Set "params=!params! %VTR% 13 10")
   rem reduce space in params string
   Set "params=!params:  = !"
   Set "params=!params: /=/!"
   Call Call :lengthCalc "%%params:~!length!%%" lengthOf & Set /A "length+=!lengthOf!"
   If !length! gtr 7600 (
      rem params length may exceed what a variable can store. do colorshow in part.
      ColorShow !params!
      Set "params=" & Set "length=0"))

If not "%bdrColors%"=="XX" (
   Set "params=%params% %indentStr% /%bdrColors% %LL% %HZ%*%bdrHZLen% %LR% 13 10")

If defined params ColorShow %params%
endlocal & exit /b

 rem __________________________ functions begin here ___________________________

:getParams [command-line entries]  [returm var: comma-delimited string of all parameters]
 rem assign variables according to switches and settings entered on the command-line.
 rem assign default setting if value missing or invalid number.
 setlocal EnableDelayedExpansion

 Set "args=%~1"
 Set "args=!args:/= /!"
 Set "args=!args:  /= /!"
 If "!args:~0,1!"==" " Set "args=!args:~1!"
 Set "args=%args:,=:%"
 Set "args=%args:;=:%"
 Call :upperCase "%args%" args

 rem assign defaults: square height & width, # across & # down,
 rem  squares colors, border colors, # of indented columns
 Set "adef=2" & Set "ddef=2"
 Set "hdef=4" & Set "wdef=8"
 Set "cdef=78" & Set "bdef=87" & Set "idef=0"

 rem assign limits to vars:
 Set "almt=30" & Set "dlmt=30"
 Set "hlmt=16" & Set "wlmt=16" & Set "ilmt=60"

 If not "%args%"=="!args:~/=!" (
    For %%t In (%args%) Do (
       Set "sw=%%t"
       If "!sw:~0,1!"=="/" (
          If "!sw:~0,2!"=="/A" Set "a=!sw:~2!"
          If "!sw:~0,2!"=="/D" Set "d=!sw:~2!"
          If "!sw:~0,2!"=="/H" Set "h=!sw:~2!"
          If "!sw:~0,2!"=="/W" Set "w=!sw:~2!"
          If "!sw:~0,2!"=="/C" Set "c=!sw:~2!"
          If "!sw:~0,2!"=="/B" Set "b=!sw:~2!" & Set "border=TRUE"
          If "!sw:~0,2!"=="/I" Set "i=!sw:~2!"
       ) Else (
           rem look for 1 or 2 ascii codes entered for fill characters
           For %%n In (!sw!) Do (
             If "!asciiCode1!"=="" (
                Call :asciiValidate "%%n" asciiCode1 asciiCode2))
       ))
    rem validate numeric entries; set to default if invalid or to maximum if limit exceeded
    For %%o In (a d h w i) Do (
       Call :numComponent "!%%o!" %%o
       If not defined %%o Set "%%o=!%%odef!"
       If !%%o! gtr !%%olmt! Set "%%o=!%%olmt!")

    rem set square & border colors to defaults if missing from command-line entry
    For %%o In (c b) Do If not defined %%o Set "%%o=!%%odef!")

    If "%b%"=="" If "%border%"=="TRUE" Set "b=87"
    If "%b%"=="+" Set "b=8+"
    If not "%b%"=="%b:XX=%" (
       Set "vWide=FALSE"
    ) Else (
       If not "%b%"=="%b:+=%" (
          Set "vWide=TRUE" & rem border verticals will be 2 columns wide
          Set "b=%b:+=%"
          Set "b=!b:~0,1!" & rem remove 2nd color code if it was there
       ) Else (Set "vWide=FALSE"))

 rem if 2 sets of color codes were entered, break out into 2 vars,
 rem otherwise assign the same color codes to the 2 vars.
 If not "%c%"=="!c::=!" (
    For /F "tokens=1,2 delims=:" %%m In ("%c%") Do (
       Set "colorCodes1=%%m" & Set "colorCodes2=%%n")
    ) Else (Set "colorCodes1=%c%" & Set "colorCodes2=%c%")

 rem assign default values to parameters not defined
 For %%o In (a d w h i) Do If not defined %%o Set "%%o=!%%odef!"
 rem these vars can not be 0
 For %%o In (a d w h) Do If "!%%o!"=="0" Set "%%o=!%%odef!"
 If %a% lss 2 Set "a=2" & rem across minimum is 2
 If not defined asciiCode1 Set "asciiCode1=32"
 If not defined asciiCode2 Set "asciiCode2=32"

 Set "parmsStr=%a%,%d%,%w%,%h%,%colorCodes1%,%colorCodes2%,%b%,%i%,%asciiCode1%,%asciiCode2%,%vWide%"
 endlocal & set "%~2=%parmsStr%" & exit /b
 rem ______________________________ end getParams ______________________________

:upperCase
 rem convert letters in %1 to uppercase. assign converted string to %2
 setlocal EnableDelayedExpansion
 For /F "delims=" %%a In ("%~1") Do (
    Set "chars=%%a"
    For %%b In (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) Do (
       Set "chars=!chars:%%b=%%b!"
 ))
 endlocal & set "%~2=%chars%" & exit /b
 rem ______________________________ end upperCase ______________________________

:numComponent [string] [return var]
 rem return numeric component at trailing end of string or return 0.
 setlocal

 Set "chars=%~1"
 Set "chars=%chars: =%"
 Set "validChars=0 1 2 3 4 5 6 7 8 9"
 Set "numbs="

 rem save numeric characters at end of string until non-numeric char is found.
 :topNC
 Set "numer="
 Set "temp=%chars:~-1%"

 For %%i In (%validChars%) Do If "%temp%"=="%%i" Set "numer=%%i" & GoTo:nextNC
 :nextNC
 If not "%numer%"=="" (Set "numbs=%numer%%numbs%") Else GoTo:endNC
 Set "chars=%chars:~0,-1%"
 GoTo:topNC
 :endNC

 If "%numbs%"=="" Set "numbs=0"
 Set /A "numbs=%numbs%*1" & rem this would remove leading 0

 endlocal & set "%~2=%numbs%" & exit /b
 rem ______________________________ end numComponent ___________________________

:asciiValidate [string to validate] [ret var ascii code #1] [ret var ascii code #2]
 rem validate %1 for numeric value or two delimited values in the range 1-255.
 setlocal EnableDelayedExpansion

 Set "str=%~1"
 For /F "tokens=1* delims=:" %%a In ("%str%") Do Set "val1=%%a" & Set "val2=%%b"

 Call :numComponent "%val1%" val1
 If not "%val2%"=="" Call :numComponent "%val2%" val2
 If "%val2%"=="" (Set "loopCount=1") Else Set "loopCount=2"

 For /L %%n In (1,1,%loopCount%) Do (
    Set "var=val%%n"
    Set /A "x=!val%%n!"
    If !x! lss 1 (
       Set "!var!=1"
    ) Else If !x! gtr 255 (
       Set "!var!=255"))

 rem if ascii code # is restricted, change it to code #32 (a blank)
 For /L %%n In (1,1,%loopCount%) Do (
    For %%c In (7 8 9 10 13) Do If %%c equ !val%%n! Set "val%%n=32"
 )

 If "%val2%"=="" Set "val2=32"

 endlocal & Set "%~2=%val1%" & Set "%~3=%val2%" & exit /b
 rem ______________________________ end asciiValidate __________________________

:lengthCalc
 rem lengths will be accumulated to calculate length of parameters string.

 setlocal EnableDelayedExpansion
 Set "tmpfile=temp.tmp"

 >"%tmpfile%" echo %~1
 Set "length=0"

 For /F "usebackq" %%I In ('%tmpfile%') Do Set /A "length=%%~zI-2"
 If EXIST temp.tmp DEL temp.tmp

 endlocal & Set "%~2=%length%" & exit /b
 rem:_______________________________end lengthCalc______________________________

:showSamples
 setlocal EnableDelayedExpansion

 Set "count=0"
 for /f "tokens=1,* delims=@:" %%a in ('findstr /bn "@:" "%~f0" ') do (
    Set "line=%%b"
    If "!line!"=="" Set "line= "
    Set "arrayTxt[!count!]=!line!"
    Set /A "count+=1")

 Set /A "count-=1"

 For /L %%n In (1, 1, %count%) Do (
    colorshow /0e arrayTxt[%%n] 13 10)

 colorshow 13 10 /0b " Press Enter to view samples, or Ctrl+C to halt the batch file." 13 10
 pause>nul

 for /f "tokens=1,* delims=:::" %%a in ('findstr /bn ":::" "%~f0" ') do (
    Set "line=%%b"
    colorshow /0f "!line!" 13 10 & Call %~f0 !line! & pause)

 endlocal & exit /b
 rem ______________________________ end showSamples_____________________________
Last edited by Jer on 30 Oct 2016 00:04, edited 4 times in total.

Thor
Posts: 43
Joined: 31 Mar 2016 15:02

Re: Batch Script to make ColorShow Checkerboards

#2 Post by Thor » 27 Oct 2016 10:34

Very cool!
Here is my chessboard sample:

Code: Select all

checkboard.bat  /a8 /d8 /w6 /h3 /c0f /i0 /bbb

But I've noticed the border width from top/bottom are not the same as left/right.
Could you fix that?

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Batch Script to make ColorShow Checkerboards

#3 Post by Jer » 27 Oct 2016 17:19

The batch code has been updated with your suggestion. You can now choose a
solid-color border that has 2-column wide border verticals by adding
a plus symbol at the end of the /b switch.

Code: Select all

/a3 /d3 /w12 /h4 /c91 /b1+ /i2

Jerry

Thor
Posts: 43
Joined: 31 Mar 2016 15:02

Re: Batch Script to make ColorShow Checkerboards

#4 Post by Thor » 27 Oct 2016 19:52

Thanks Jer, the problem has been fixed now.

Thor
Posts: 43
Joined: 31 Mar 2016 15:02

Re: Batch Script to make ColorShow Checkerboards

#5 Post by Thor » 28 Oct 2016 06:14

Could you make the "a" and "d" switches to have different sizes? Like "small" "medium" "large" instead of only one size like right now?

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Batch Script to make ColorShow Checkerboards

#6 Post by Jer » 28 Oct 2016 10:20

You already have control of sizes for width and height of the squares, i.e., /w8 /h4
and the numeric entries with the /a and /d switches determine how many squares
across and down: /a8 /d6

I am puzzled by your asking for "small" "medium" "large" checkerboards when you can
make those now and everything in between.

Thor
Posts: 43
Joined: 31 Mar 2016 15:02

Re: Batch Script to make ColorShow Checkerboards

#7 Post by Thor » 28 Oct 2016 17:59

You've right. I've forgot about the /w and /h switches which could increase and decrease the width and height. Sorry for such an awkward request. :oops:

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Batch Script to make ColorShow Checkerboards

#8 Post by misol101 » 29 Oct 2016 04:21

Nice idea.

Here's another implementation using my tool gotoxy (viewtopic.php?f=3&t=7129), since you don't seem to mind using external binaries.

It's only about 20% as big, but to be fair I only allow arguments in a specific order.

Pros:
1. No limitation of size, length of command line is not a problem
2. More complex patterns possible, as evidenced by e.g. the third new example, which shades the colors
3. Faster

Cons:
Basic understanding of gotoxy control codes needed. Basically, use \90 to say foreground color 9, background color 0. Use \g20 to specify a blank character (Hex 20=32). Characters must be specifed in hex, OR if they're "normal" characters they can be written as-is.

Code: Select all

@echo off
setlocal
if "%~1" == "?" call :EXAMPLES&goto :eof
if "%~7" == "" echo. & echo Usage: checkers repeatx width repeaty height indent pattern1 pattern2 [bordercolor^|-] [altpattern1^|-] [altpattern2^|-] [borderWidthMulHack]& echo. & echo Write checkers ? for examples&goto :eof
set /a GECHO=0, ARG1=%1, ARG2=%2 & shift & shift
call :MAKECHECKERS %ARG1% %ARG2% %1 %2 %3 %4 %5 %6 %7 %8 %9
endlocal
goto :eof

:EXAMPLES
set GECHO=1
call :MAKECHECKERS 2 20 1 8 1 \0e\g20 \04\g20 \e0
call :MAKECHECKERS 8 6 8 2 6 \0f\g20 \00\g20 \70
call :MAKECHECKERS 4 6 4 2 6 \02\g20 \0a\g20 \76
call :MAKECHECKERS 3 12 3 6 4 \01\g20 \0b\g20 \80
call :MAKECHECKERS 5 10 4 5 2 \e4\gdd \c2\gb2 \74 \c2\gdd \e4\gb2
call :MAKECHECKERS 4 9 4 4 1 \1f\gb0 \26\gb1 \10 \62\gb0 \f1\gb1
call :MAKECHECKERS 20 1 8 1 20 \f1\g0f \0e\gc5 \22 \0e\g0f \f1\gc5
call :MAKECHECKERS 3 11 3 5 1 \fa\gdc \c4\gdc \22
call :MAKECHECKERS 20 2 20 1 2 \05\g20 \0e\g20 \e2
call :MAKECHECKERS 3 9 3 4 1 \0e\gb0 \e0\gc5 \ee \e0\gb0 \1e\gc5
call :MAKECHECKERS 10 5 10 2 1 \ea\gb2 \38\gb0 \00 \83\gb0 \ae\gb2
:: New examples
call :MAKECHECKERS 76 1 40 1 1 \f7\gb2 \b1\gb1 \c0
call :MAKECHECKERS 16 1 12 3 5 \f7Y0L0 \b1$wAG -
call :MAKECHECKERS 12 1 12 3 3 \00\01\gb2\gb1\gb0\g20\91\gb0\g20 \00\04\gb2\gb1\gb0\g20\c4\gb0\g20 \f0 \00\02\gb2\gb1\gb0\g20\e2\gb0\g20 \00\05\gb2\gb1\gb0\g20\d5\gb0\g20 6
call :MAKECHECKERS 9 1 7 3 10 \00\01\gb2\gb1\gb0\g20\91\gb0\g20 \00\04\gb2\gb1\gb0\g20\c4\gb0\g20 \70 - - 6
call :MAKECHECKERS 12 6 8 4 3 \g20 \0+\gdb \f1
call :MAKECHECKERS 7 5 5 6 4 \gdc\//\gdf \+0\g07\++\g07 \50 - - 2
set GECHO=0
call :MAKECHECKERS 19 4 12 3 0 \01\g20 \00\g20 - & gotoxy 0 /36 & call :MAKECHECKERS 11 7 7 5 0 \09\g20 \- \70 & pause
call :MAKECHECKERS 20 4 12 3 0 \21\gb0 \00\g20 - & gotoxy 0 /36 & call :MAKECHECKERS 5 16 4 9  0 \09\0q\g20 \- \70 & pause
goto :eof

:MAKECHECKERS
setlocal
set /a ARGTEMP=%1, ARGTEMP2=%2, ACROSS=%1/2, WIDTH=%2, DOWN=%3/2, HEIGHT=%4, AREST=%1 %% 2, DREST=%3 %% 2, BORDERW=%1*%2, BORDERH=%3*%4, SPC=%5
set PATT1=%6&set PATT2=%7&set PATT3=%7&set PATT4=%6
set BK=\78&if not "%~8" == "" set BK=%8
if not "%~9" == "" if not "%~9" == "-" set PATT3=%9
shift & shift
if not "%~8" == "" set XP=%8& if not "%~8" == "-" set PATT4=%8
if not "%~9" == "" set /a BORDERW*=%9&set XP2=%9
if not %BK%==x if not %BK%==xx if not %BK%==- set UBORDER=%BK%\gDA\M%BORDERW%{\gC4}%BK%\gBF\n& set DBORDER=%BK%\gC0\M%BORDERW%{\gC4}%BK%\gD9\n& set HBORDER=%BK%\gB3

if %AREST%==1 set ODDHP1=\M%WIDTH%{%PATT1%\\}&set ODDHP2=\M%WIDTH%{%PATT3%\\}
set PATTERN1=\M%HEIGHT%{%HBORDER%\M%ACROSS%{\M%WIDTH%{%PATT1%\\\}\M%WIDTH%{%PATT2%\\\}\\}%ODDHP1%%HBORDER%\n\}
set PATTERN2=\M%HEIGHT%{%HBORDER%\M%ACROSS%{\M%WIDTH%{%PATT3%\\\}\M%WIDTH%{%PATT4%\\\}\\}%ODDHP2%%HBORDER%\n\}
set PATTERN=%UBORDER%\M%DOWN%{%PATTERN1%%PATTERN2%}
if %DREST%==1 set PATTERN=%PATTERN%\M1{%PATTERN1%}
if %GECHO% == 1 gotoxy k k "%ARGTEMP% %ARGTEMP2% %1 %2 %3 %4 %5 %6 %7 %XP% %XP2%" f 0 csiw& echo. & echo.&set PAUSE=pause
gotoxy %SPC% k "%PATTERN%%DBORDER%\p0;k" 0 0 csx & %PAUSE%
endlocal


Image
Last edited by misol101 on 16 Apr 2017 14:36, edited 3 times in total.

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Batch Script to make ColorShow Checkerboards

#9 Post by misol101 » 29 Oct 2016 17:41

Added 4 more examples. Example 5 and 6 uses + and / to change colors during creation. The results can quickly get chaotic, as example 6 shows :)

Example 7 and 8 uses overlay and transparency to put two checkerboards on top of each other. In example 8, the top layer is "semi-transparent"

Jer
Posts: 177
Joined: 23 Nov 2014 17:13
Location: California USA

Re: Batch Script to make ColorShow Checkerboards

#10 Post by Jer » 30 Oct 2016 00:04

edit 10/30/2016 - removed unnecessary code from randNumb function: Set /A "numb*=1"

This thread is now checkered in more ways than one.
Revisions to the code in the top post were completed and updated today.
Name the file cboard.bat if you will be trying out cbr.bat entered below.

A way was needed to work with variable contents as it approached capacity limit.
Cboard.bat does that by accumulating length along the way, at the bottom of a For loop,
then doing the colorshow.exe display before going over the limit, and then continuing by
filling the emptied variable for the next call to colorshow. Because of this revision, I hope to
never see the “line too long” error. The squares across and down maximums are increased from 20 to 30.

And now to make this even more checkered, a new batch file companion to cboard.bat
has been added that I call cbr.bat. Designed to bring order to chaos, it will show you
a bazillion boards, each one patterned from a random set of parameters. It may be too much
of a good thing, like overdosing on candy.

Cbr.bat is run with no args and calls cboard.bat. Aacini’s random number method was used in cbr.bat.
My plan was to create randomness with each cboard.bat switch, and every board to be unique in size,
colors, content and borders.

If you run cbr.bat, your DOS window layout should accommodate at least 135 columns and 35 lines.
ColorShow.exe must be in your current folder.

cbr.bat:

Code: Select all

@Echo Off
rem Batch script displays checkered and patterned boards of random size and colors.
rem Calls: cboard.bat
rem Other required file: ColorShow.exe
:::
::: script will run in continuous viewing mode,
::: include /q as an argument to display just 1 board.
:::
::: with borders included, boards could be as wide as 135 columns across and 32 lines.
:::

If not EXIST ColorShow.exe Echo The file colorshow.exe was not found in this folder.  Exiting.& GoTo:eof
If not EXIST cboard.bat Echo The file cboard.bat was not found in this folder.  Exiting.& GoTo:eof

setlocal EnableDelayedExpansion

If /I "%1%"=="/Q" (Set "quitMode=yes") Else Set "quitMode="
Set "choices= q"
Set "char[1]=124" & Set "char[2]=176" & Set "char[3]=177" & Set "char[4]=178"
Set "char[5]=179" & Set "char[6]=186" & Set "char[7]=197"
Set "char[8]=205" & Set "char[9]=206"
Set "char[10]=216" & Set "char[11]=219"
Set "char[12]=220" & Set "char[13]=221"
Set "char[14]=222" & Set "char[15]=223"
Set "char[16]=240" & Set "char[17]=249"
Set "char[18]=250" & Set "char[19]=254"

:top
Call :randNumb "0" "15" c1
Call :randNumb "0" "15" c2
If %c1% equ %c2% Set /A "c2=((!c2!+18)%%16)+1"
Call :randNumb "0" "15" c3
Call :randNumb "0" "15" c4
If %c3% equ %c4% Set /A "c4=((!c3!+18)%%16)+1"

Call :colorCodes "%c1%" color1
Call :colorCodes "%c2%" color2
Call :colorCodes "%c3%" color3
Call :colorCodes "%c4%" color4

Call :randNumb "1" "2" s
If %s% equ 2 (
   Set "sqColors=%color1%%color2%:%color3%%color4%"
   Call :randNumb "1" "19" j
   Call :randNumb "1" "19" k
   Call :randNumb "0" "8" u
   If !u! gtr 0 (
      Call Set "asciiChars=%%char[!j!]%%:%%char[!k!]%%"
   ) Else (Call Set "asciiChars=%%char[!j!]%%")
) Else (
   Set "sqColors=%color1%%color2%"
   Set "asciiChars=")

rem board not too small and not too big:
Call :randNumb "4" "18" across
Call :randNumb "4" "18" down

If %down% gtr %across% If %down% leq 8 (
   Set "t=%down%"
   Set "down=!across!" & Set "across=!t!")

If %across% gtr %down% (
   Set /A "d=%across%-%down%"
) Else If %down% gtr %across% (
   Set /A "d=%down%-%across%"
) Else (Set "d=0")

If %d% gtr 8 (
   If %across% gtr %down% (Set /A "across=!across!-8") Else Set /A "down=!down!-8")
If %down% equ 1 Call :randNumb "1" "3" down

Set /A "t=%across%*%down%"
If %t% gtr 375 (
   Set "wMax=3" & Set "hMax=1"
) Else If %t% gtr 350 (
   Set "wMax=3" & Set "hMax=2"
) Else If %t% gtr 300 (
   Set "wMax=4" & Set "hMax=2"
) Else If %t% gtr 250 (
   Set "wMax=5" & Set "hMax=3"
) Else If %t% gtr 200 (
   Set "wMax=6" & Set "hMax=3"
) Else If %t% gtr 150 (
   Set "wMax=7" & Set "hMax=3"
) Else If %t% gtr 75 (
   Set "wMax=10" & Set "hMax=3"
) Else If %t% gtr 50 (
   Set "wMax=12" & Set "hMax=4"
) Else (Set "wMax=14" & Set "hMax=5")

Call :randNumb "2" "%wMax%" width

Set /A "s=%across%*%width%"
If %s% geq 100 (
   For /L %%m In (1,1,2) Do (
      Set /A "m=%across%*!width!"
      If !m! geq 100 Set /A "width=!width!/2")
) Else If %s% lss 30 (
   Call :randNumb "8" "10" width)

If %across% leq 3 (
   If %width% equ 1 Call :randNumb "8" "9" width
   If %width% equ 2 Call :randNumb "6" "7" width
   If %width% equ 3 Call :randNumb "5" "6" width)

If %width% leq 2 If %across% lss 20 (
   Set /A "s=%across%*%width%"
   If !s! leq 20 Call :randNumb "18" "20" width)

rem width should be no greater than 128 columns
For /L %%n In (1,1,2) Do (
   Set /A "s=!across!*%width%"
   If !s! gtr 128 Set /A "across-=1")

Call :randNumb "1" "%hMax%" height

Set /A "s=%down%*%height%"
If %s% geq 30 (
   Set "flag30=TRUE"
   If %height% gtr 5 Set /A "height=%height%/2"
   If %down% gtr 12 Set /A "down=12")

If %height% leq 3 Call :randNumb "1" "3" height
Set /A "s=%down%*%height%"
If %s% gtr 30 If %height% gtr 2 Call :randNumb "1" "2" height

For /L %%n In (1,1,2) Do (
   If !height! gtr %width% (
      Set /A "s=!height!-%width%"
      If !s! geq 2 Set /A "height=!height!/2"))

rem height may have exceeded 30 lines with the above changes. revise if needed.
Set /A "s=%down%*%height%"
If %s% gtr 30 (
   Set /A "height=%height%/2"
) Else If %s% leq 10 If %height% leq 2 (
   Set /A "height*=2"
) Else ( If %s% leq 10 Set /A "down+=2")

If "%flag30%"=="TRUE" (
  rem height was reduced. see if there's room for a few more lines
  Set /A "s=%down%*%height%"
  If !s! leq 16 (
     rem squares down will be added
     Set /A "down=!down!+((20-!s!)/2)"))

rem a random chance to display a 20x20 or 25x25 board
If %height% equ 1 If %width% leq 3 (
   Call :randNumb "1" "4" r
   If !r! equ 3 (
      Set "across=20" & Set "down=20"
   ) Else If !r! equ 4 (
      Set "across=25" & Set "down=25"))

Call :randNumb "1" "3" r

If %r% geq 2 (
   rem a border will be added
   Call :randNumb "0" "15" r1
   Call :randNumb "0" "15" r2
   Call :colorCodes "!r1!" code1
   Call :colorCodes "!r2!" code2
   Call :randNumb "1" "3" z
   If !z! equ 2 (
      Set "bdr=/b!code1:~0,1!!code2:~0,1!"
   ) Else If !z! equ 1 (
      Set "bdr=/b!code1!!code1!"
   ) Else (
      Call :randNumb "0" "4" s
      If !s! equ 0 (
         Set "bdr=/b!code1!!code1!"
      ) Else If !s! leq 3 (
         Set "bdr=/b!code1!+"
      ) Else (
         Call :randNumb "0" "1" p
         If !p! equ 0 (Set "bdr=/b!code1!") Else Set "bdr=/b!code1!!code2!"))
) Else ( Set "bdr=/bxx" )


Call :randNumb "0" "2" x
If %x% equ 0 (Set "indent=") Else Set "indent=/i%x%"

Set "str=/a%across% /d%down% /w%width% /h%height% /c%sqColors% %bdr% %indent% %asciiChars%"
Set "str=%str:  = %"
Call cboard.bat %str%
ColorShow 13 10 /0e 32 "%str%" 32*4 /0b "Press spacebar to Continue, q to Quit" 13 10

If "%quitMode%"=="yes" GoTo:eof
<nul set /p "="
Call :choice %choices%
If !errorlevel! equ 3 GoTo:eof
GoTo:top

endlocal & exit /b

::_______________________functions begin here_____________________________________

:randNumb [min value] [max value] [ret var]
 rem return a random number in the range %1 to %2
 setlocal EnableDelayedExpansion

 Set /A "varMin=%~1 - 1"
 Set "varMax=%~2"
 Set /A "varScope=%varMax%-%varMin%"

 Set "Rand(x)=( (x)*^!random^!/32768+1 )"
 Set /A numb=%Rand(x):x=!varScope!% + !varMin!

 endlocal & set "%~3=%numb%" & exit /b
::_______________________end randNumb_____________________________________________

:colorCodes [char position] [out single color code]
 setlocal EnableDelayedExpansion

 Set "codes=0123456789abcdef"
 Set "pos=%~1"
 For /L %%n In (%pos%,1,%pos%) Do Set "charOut=!codes:~%%n,1!"

 endlocal & Set "%~2=%charOut%" & exit /b
::_______________________end colorCodes___________________________________________

:choice
 setlocal

 Set KEY=
 Set "errlvl="

 For /f "delims=" %%a In ('Xcopy /l /W "%~f0" "%~f0" 2^>nul') Do (
    If Not defined KEY Set "KEY=%%a")

 Set KEY=%KEY:~-1%

 setlocal EnableDelayedExpansion
 If "%KEY%"=="" Set "errlvl=0"
 If "%KEY%"==" " Set "errlvl=0"
 If /I "%KEY%"=="Q" Set "errlvl=3"
 If not "%errlvl%"=="" endlocal & endlocal & exit /b %errlvl%

 endlocal & GoTo:choice
::_______________________end choice_______________________________________________

misol101
Posts: 475
Joined: 02 May 2016 18:20

Re: Batch Script to make ColorShow Checkerboards

#11 Post by misol101 » 31 Oct 2016 03:19

You want checkerboards?? You can't handle checkerboards!!

Umm... :) So anyway I put some checkerboard patterns on a rotating box surrounded by... checkerboards.

Was going to attach file, but.. 100k limit.. Ok, it's here (also includes previous checkers.bat): http://www.mediafire.com/file/apsv7fv44gglm89/checkerbox.zip

Press SPACE while running.

Image

Oh, and try running checkerbox.bat with a parameter too (any will do), then pixel font is used instead.

Post Reply