You are not logged in.

#1 28 Dec 2013 02:47

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

[Batch Utility] Colors (Pattern-generator) by Evanator

This is f***ing witchcraft. It is.
Well, this thing requires DEBUG (only on x86 [32 bit] machines).
------------------------------------------------------------------

Well would you look at this:
pattern1screenshot_zpsbfcfd6b6.jpg

I generated this with Colors, and you can generate beautiful blocky pictures like that one by simply executing it, maybe specifying a seed, and waiting.
It takes a while to generate a picture, but goddamn it, it's GENERATED!

Here's the link: batchosforum.webs.com/downloads
It's under 'Apps'.

If you don't want to download it, here's the source:

@echo off
title Colors
set x=0
set y=0
set operator1=+
set operator2=*
set operator3=-
set Hexa=0
set color=1
set random=
set /a randa=(%random% / 700)
set /a randb=%random%

set interval_var=0
set interval=23

set char=°
:warning
cls
echo.
echo. Seed: %randa% (type 'seed' to change)
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art!     []
echo.                           []
echo.  Continue?
echo.                           ()
set choice=
set /p choice=(Y/N/seed):
if not defined choice goto :warning
if /i "%choice%"=="y" (cls&goto :colorstart0)
if /i "%choice%"=="n" (cls&goto :eof)
if /i "%choice%"=="seed" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set /p randa=^>^>
  echo.
  echo. The seed has been changed.
  ping localhost -n 2 >nul
)
goto :warning

:colorstart0
echo. @echo off>>%randb%-color.bat
echo. ::Color made by Evan Theilig>>%randb%-color.bat
echo. ::www.batchosforum.webs.com>>%randb%-color.bat
echo. >>%randb%-color.bat
echo. ^(>>%randb%-color.bat
:colorstart
set /a y=y %operator1% 1
if "%operator3%"=="-" (set operator3=+&goto :colorstart2)
if "%operator3%"=="+" (set operator3=-&goto :colorstart2)

:colorstart2
set /a interval_var=interval_var + 1

if "%y%"=="50" (
set operator1=-
set operator2=+
set /a x=x+1
)

if "%y%"=="-1" (
set operator1=+
set operator2=*
set /a x=x+1
)

if "%x%"=="80" (goto :end)

REM The algorithm for the pattern.

set /a color=(x %operator1% y) %operator3% randa %operator1% (y %operator2% 2)


call:d2h_2 %color%
Set /a "G=%Y% * 160 + (%X% + 1 - 1) * 2
call:d2h %G%
(Echo.EB800:%Hexa% "%char%" %Hexa_2%
 Echo.Q
)|Debug >nul 2>&1

echo. Echo.EB800^:%Hexa% "%char%" %Hexa_2% >>%randb%-color.bat
if "%interval_var%"=="%interval%" (
  echo. Echo.Q >>%randb%-color.bat
  echo. ^)^|Debug ^>^nul 2^>^&^1 >>%randb%-color.bat
  echo. ( >>%randb%-color.bat
  set interval_var=0
)
goto :colorstart


:d2h
set hstr=0123456789ABCDEF&& set int=%1&& set last=
:loop
set/a ths=%int%%%16
call set last=%%hstr:~%ths%,1%%%last%
if /i %int% geq 16 (set /A int=%int%/16
) else (Set Hexa=%last%&& goto:eof)
goto:loop

:d2h_2
set hstr=0123456789ABCDEF&& set int=%1&& set last=
:loop_2
set/a ths=%int%%%16
call set last=%%hstr:~%ths%,1%%%last%
if /i %int% geq 16 (set /A int=%int%/16
) else (Set Hexa_2=%last%&& goto:eof)
goto:loop_2

:end
echo.^)^|Debug ^>nul ^2^>^&^1 >>%randb%-color.bat
echo.pause ^>nul>>%randb%-color.bat
echo.exit ^/b>>%randb%-color.bat
(Echo.EB800:A54 " " 0F
Echo.EB800:A56 "S" 0F
Echo.EB800:A58 "a" 0F
Echo.EB800:A5A "v" 0F
Echo.EB800:A5C "e" 0F
Echo.EB800:A5E "d" 0F
Echo.EB800:A60 "!" 0F
Echo.EB800:A62 " " 0F
 Echo.Q
)|Debug >nul 2>&1
pause >nul
goto :eof

Feel free to post the images you generate!

Offline

#2 28 Dec 2013 13:01

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

I was entertained by it. smile

I had a crack at optimising it a little - This version creates the file and then displays it.
Optionally, if you clear the file variable it will create the image interactively.

This version allows you to change the screen size, lines and columns.
There is also a runtime.txt file which tracks how long it took

There's a version that creates a random artwork following this code, which is very quick.


@echo off
:: set "file=" to disable file creation
set "file=1"
set cols=80
set lines=50
set e=!
setlocal enabledelayedexpansion
title Colors
:begin
set x=0
set y=0
set operator1=+
set operator2=*
set operator3=-
set Hexa=0
set color=1
set hstr=0123456789ABCDEF

for /L %%a in (1,1,!random!) do set randa=!random!
set /a randa=(%random% / 700)

set interval_var=0
set interval=23

set char=°
:warning
mode con cols=%cols% lines=%lines%
cls
echo.
echo. Seed: %randa% 
echo.
echo  R for random
echo  M for manual entry
echo  Q to quit
echo.
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art!e!     []
echo.                           []
echo.  Enter to continue
echo.                           ()
set choice=
set /p "choice=(R,M,Q,Enter): "
if /i "%choice%"=="" (cls&goto :colorstart0)
if /i "%choice%"=="Q" (cls&goto :eof)
if /i "%choice%"=="R" (goto :begin)
if /i "%choice%"=="M" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set "randa="
  set /p "randa=>> "
  if not defined randa goto :begin
  echo.
  echo. The seed has been changed to !randa!
  ping localhost -n 2 >nul
)
goto :warning


:colorstart0

set time1=%time%
set "filename=Color [%randa%] - %random%.bat"
if defined file (
echo Creating file "%filename%" - please wait
) else (
goto :colorstart
)

 >"%filename%" echo.@echo off
>>"%filename%" echo. ::Color made by Evan Theilig
>>"%filename%" echo. ::www.batchosforum.webs.com
>>"%filename%" echo.
>>"%filename%" echo. :: seed=%randa%
>>"%filename%" echo.mode con cols=%cols% lines=%lines%
>>"%filename%" echo. ^(

:colorstart
set /a y=y %operator1% 1

if "%operator3%"=="-" (
set operator3=+
) else (
set operator3=-
)
set /a interval_var=interval_var + 1

if "%y%"=="%lines%" (
set operator1=-&set operator2=+&set /a x=x+1
) else if "%y%"=="-1" (
set operator1=+&set operator2=*&set /a x=x+1
)

if "%x%"=="80" (goto :end)

REM The algorithm for the pattern.

set /a color=(x %operator1% y) %operator3% randa %operator1% (y %operator2% 2)
Set /a "G=%Y% * 160 + (%X% + 1 - 1) * 2

set "step2="
set "hexa="
set "hexa_2="
set int=%color%& set last=
:loop
set/a ths=%int%%%16
set last=!hstr:~%ths%,1!%last%
if /i %int% geq 16 (set /A int=%int%/16 & goto :loop)
if not defined hexa_2 Set "Hexa_2=%last%"
if not defined step2 set int=%G%& set last=&set step2=1&goto :loop
if not defined hexa Set "Hexa=%last%"

if not defined file (
     (Echo.EB800:%Hexa% "%char%" %Hexa_2%
      echo Q
     )|Debug >nul
) else (
     set /p "=." <nul
  >>"%filename%" echo. Echo.EB800^:%Hexa% "%char%" %Hexa_2%
if "%interval_var%"=="%interval%" (
  >>"%filename%" echo. Echo.Q
  >>"%filename%" echo. ^)^|Debug ^>^nul 2^>^&^1
  >>"%filename%" echo. (
  set interval_var=0
)
)
goto :colorstart




:end
set time2=%time%
>>runtime.txt echo file=%filename% - mod %time1% - %time2%
if defined file (
>>"%filename%" Echo.echo Q
>>"%filename%" echo.^)^|Debug ^>nul ^2^>^&^1
>>"%filename%" echo.pause ^>nul
>>"%filename%" echo.exit ^/b
(Echo.EB800:A54 " " 0F
Echo.EB800:A56 "S" 0F
Echo.EB800:A58 "a" 0F
Echo.EB800:A5A "v" 0F
Echo.EB800:A5C "e" 0F
Echo.EB800:A5E "d" 0F
Echo.EB800:A60 "%e%" 0F
Echo.EB800:A62 " " 0F
Echo.Q
)|Debug >nul 2>&1
"%filename%"
)
pause >nul

Here is another version that creates a random artwork - it uses VBS to create the batch file and then launches the batch file.


@echo off
set vbs="%temp%\Random art.vbs"
more +15 "%~f0" >%vbs%
:loop
set file="Random Art - %random%.bat"
if exist %file% goto :loop
cscript /nologo %vbs% %file%
del %vbs%
%file%
goto :EOF






  Const ForReading = 1, ForWriting = 2

'  infile = "infile.txt"   '<= Set input file here
  Randomize
  filenum=cint(Rnd*32000)+cint(Rnd*32000)+cint(Rnd*32000)
  outfile = "Colour - " & filenum & ".bat" '<= Set output file here

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set objArgs = WScript.Arguments
  outfile =objargs(0)

'  Set f1 = fso.OpenTextFile(infile, ForReading)
  Set f2 = fso.OpenTextFile(outfile, ForWriting, True)

  c = 0
  dim unshuffled(4095)
  for b = 0 to 8191 step 2  
  unshuffled(c) = hex(b)
  c = c + 1
  next

'Auric - http://www.vistax64.com/vb-script/184525-randomize-one-dimentional-array.html
'Randomise array
  Dim Shuffled(4095)
  Dim L, card
  Randomize Timer
  For L = 4095 To 0 Step -1
  card = Int(Rnd * (L + 1))
  Shuffled(L) = unShuffled(card)
  If card <> L Then unShuffled(card) = unShuffled(L)
  Next

  f2.writeline "@echo off"
  f2.writeline "mode con cols=80 lines=50"

  f2.writeline "("
  for b = 0 to 4095  
  num=cint(rnd*255)
  f2.writeline "echo eb800:" & shuffled(b) & " " & chr(34) & "°" & chr(34) & " " & hex(num)
  if not b = 0 then if b mod 256 = 0 then f2.writeline "echo Q)|Debug >nul": f2.writeline "("
  next

  f2.writeline "echo Q)|Debug >nul"
  f2.writeline "pause>nul"
  f2.Close

Last edited by foxidrive (28 Dec 2013 13:06)

Offline

#3 29 Dec 2013 02:07

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

foxidrive wrote:

I was entertained by it. smile

I had a crack at optimising it a little - This version creates the file and then displays it.
Optionally, if you clear the file variable it will create the image interactively.

This version allows you to change the screen size, lines and columns.
There is also a runtime.txt file which tracks how long it took

There's a version that creates a random artwork following this code, which is very quick.


@echo off
:: set "file=" to disable file creation
set "file=1"
set cols=80
set lines=50
set e=!
setlocal enabledelayedexpansion
title Colors
:begin
set x=0
set y=0
set operator1=+
set operator2=*
set operator3=-
set Hexa=0
set color=1
set hstr=0123456789ABCDEF

for /L %%a in (1,1,!random!) do set randa=!random!
set /a randa=(%random% / 700)

set interval_var=0
set interval=23

set char=°
:warning
mode con cols=%cols% lines=%lines%
cls
echo.
echo. Seed: %randa% 
echo.
echo  R for random
echo  M for manual entry
echo  Q to quit
echo.
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art!e!     []
echo.                           []
echo.  Enter to continue
echo.                           ()
set choice=
set /p "choice=(R,M,Q,Enter): "
if /i "%choice%"=="" (cls&goto :colorstart0)
if /i "%choice%"=="Q" (cls&goto :eof)
if /i "%choice%"=="R" (goto :begin)
if /i "%choice%"=="M" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set "randa="
  set /p "randa=>> "
  if not defined randa goto :begin
  echo.
  echo. The seed has been changed to !randa!
  ping localhost -n 2 >nul
)
goto :warning


:colorstart0

set time1=%time%
set "filename=Color [%randa%] - %random%.bat"
if defined file (
echo Creating file "%filename%" - please wait
) else (
goto :colorstart
)

 >"%filename%" echo.@echo off
>>"%filename%" echo. ::Color made by Evan Theilig
>>"%filename%" echo. ::www.batchosforum.webs.com
>>"%filename%" echo.
>>"%filename%" echo. :: seed=%randa%
>>"%filename%" echo.mode con cols=%cols% lines=%lines%
>>"%filename%" echo. ^(

:colorstart
set /a y=y %operator1% 1

if "%operator3%"=="-" (
set operator3=+
) else (
set operator3=-
)
set /a interval_var=interval_var + 1

if "%y%"=="%lines%" (
set operator1=-&set operator2=+&set /a x=x+1
) else if "%y%"=="-1" (
set operator1=+&set operator2=*&set /a x=x+1
)

if "%x%"=="80" (goto :end)

REM The algorithm for the pattern.

set /a color=(x %operator1% y) %operator3% randa %operator1% (y %operator2% 2)
Set /a "G=%Y% * 160 + (%X% + 1 - 1) * 2

set "step2="
set "hexa="
set "hexa_2="
set int=%color%& set last=
:loop
set/a ths=%int%%%16
set last=!hstr:~%ths%,1!%last%
if /i %int% geq 16 (set /A int=%int%/16 & goto :loop)
if not defined hexa_2 Set "Hexa_2=%last%"
if not defined step2 set int=%G%& set last=&set step2=1&goto :loop
if not defined hexa Set "Hexa=%last%"

if not defined file (
     (Echo.EB800:%Hexa% "%char%" %Hexa_2%
      echo Q
     )|Debug >nul
) else (
     set /p "=." <nul
  >>"%filename%" echo. Echo.EB800^:%Hexa% "%char%" %Hexa_2%
if "%interval_var%"=="%interval%" (
  >>"%filename%" echo. Echo.Q
  >>"%filename%" echo. ^)^|Debug ^>^nul 2^>^&^1
  >>"%filename%" echo. (
  set interval_var=0
)
)
goto :colorstart




:end
set time2=%time%
>>runtime.txt echo file=%filename% - mod %time1% - %time2%
if defined file (
>>"%filename%" Echo.echo Q
>>"%filename%" echo.^)^|Debug ^>nul ^2^>^&^1
>>"%filename%" echo.pause ^>nul
>>"%filename%" echo.exit ^/b
(Echo.EB800:A54 " " 0F
Echo.EB800:A56 "S" 0F
Echo.EB800:A58 "a" 0F
Echo.EB800:A5A "v" 0F
Echo.EB800:A5C "e" 0F
Echo.EB800:A5E "d" 0F
Echo.EB800:A60 "%e%" 0F
Echo.EB800:A62 " " 0F
Echo.Q
)|Debug >nul 2>&1
"%filename%"
)
pause >nul

Here is another version that creates a random artwork - it uses VBS to create the batch file and then launches the batch file.


@echo off
set vbs="%temp%\Random art.vbs"
more +15 "%~f0" >%vbs%
:loop
set file="Random Art - %random%.bat"
if exist %file% goto :loop
cscript /nologo %vbs% %file%
del %vbs%
%file%
goto :EOF






  Const ForReading = 1, ForWriting = 2

'  infile = "infile.txt"   '<= Set input file here
  Randomize
  filenum=cint(Rnd*32000)+cint(Rnd*32000)+cint(Rnd*32000)
  outfile = "Colour - " & filenum & ".bat" '<= Set output file here

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set objArgs = WScript.Arguments
  outfile =objargs(0)

'  Set f1 = fso.OpenTextFile(infile, ForReading)
  Set f2 = fso.OpenTextFile(outfile, ForWriting, True)

  c = 0
  dim unshuffled(4095)
  for b = 0 to 8191 step 2  
  unshuffled(c) = hex(b)
  c = c + 1
  next

'Auric - http://www.vistax64.com/vb-script/184525-randomize-one-dimentional-array.html
'Randomise array
  Dim Shuffled(4095)
  Dim L, card
  Randomize Timer
  For L = 4095 To 0 Step -1
  card = Int(Rnd * (L + 1))
  Shuffled(L) = unShuffled(card)
  If card <> L Then unShuffled(card) = unShuffled(L)
  Next

  f2.writeline "@echo off"
  f2.writeline "mode con cols=80 lines=50"

  f2.writeline "("
  for b = 0 to 4095  
  num=cint(rnd*255)
  f2.writeline "echo eb800:" & shuffled(b) & " " & chr(34) & "°" & chr(34) & " " & hex(num)
  if not b = 0 then if b mod 256 = 0 then f2.writeline "echo Q)|Debug >nul": f2.writeline "("
  next

  f2.writeline "echo Q)|Debug >nul"
  f2.writeline "pause>nul"
  f2.Close

You're a goddamn genius.
Except for when I had set different columns and lines for the first color code, it gave me...weird results. Not good weird.
And the second one if f***ing brilliant! The way it has that 'dissolve' effect is just incredible! I don't think I could've ever done anything like that!

I'm going to tinker with the code that you gave me, and see if I can improve the size and stuff. Size is now a priority. The bigger the better!

Offline

#4 29 Dec 2013 02:21

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Also, relating to the Colors version you made with the extremely quick generation (dissolves), it isn't particularly pretty, but I am truly impressed that you got it to work that well in such little time. Really, it looks like someone ejaculated a rainbow on a piece of paper. Still, I appreciate the effort in making something that fast work that fast. Fastly.

Offline

#5 29 Dec 2013 06:25

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Thanks.  Yes, there is an issue when the screen size grows past 80 columns - I see that now.


The reason why it is so fast to display is purely due to the number of invocations of debug, and how many lines are processed at once.

In my top code, and the original too, change

set interval=23
to
set interval=256


and then when the generation is complete (or my top code) the picture will display very quickly from the created batch file.

Last edited by foxidrive (29 Dec 2013 06:52)

Offline

#6 29 Dec 2013 10:36

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

I think the main reason this Batch file is slow is because the number of times that Debug is executed, as foxidrive said. Also, Debug program does not work in 64-bits Windows versions, so I modified this Batch file in order to use my ColorShow.exe auxiliary program (look for program # 12) to show complete screen lines. Although this method requires to first calculate and store all screen points and then show them in lines (because the original calculation order is by columns), this method is still faster (and simpler) than the former one. This is my version:

@echo off
setlocal EnableDelayedExpansion

title Colors
set /A x=0, y=0, randa=(%random% / 700), cols=0, lines=0
for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !lines! equ 0 ( set lines=%%a
   ) else if !cols! equ 0 ( set cols=%%a
   )
)

ECHO LINES=%LINES%, COLS=%COLS% > LOG.TXT
ECHO START - %TIME% >> LOG.TXT

set operator1=+
set operator2=*
set operator3=-
set plusminus[+]=-
set plusminus[-]=+

set hstr=0123456789ABCDEF
set char=176

:warning
cls

echo.
echo. Seed: %randa% (type 'seed' to change)
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art.     []
echo.                           []
echo.  Continue?
echo.                           ()
set choice=
set /p choice=(Y/N/seed):
if not defined choice goto :warning
if /i "%choice%"=="y" (cls&goto :colorstart)
if /i "%choice%"=="n" (cls&goto :eof)
if /i "%choice%"=="seed" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set /p randa=^>^>
  echo.
  echo. The seed has been changed.
  ping localhost -n 2 >nul
)
goto :warning

::Color made by Evan Theilig
::www.batchosforum.webs.com

:colorstart
set /A y=y %operator1% 1
set operator3=!plusminus[%operator3%]!

if %y% equ %lines% (
   set operator1=-
   set operator2=+
   set /A x+=1
   set /P "=." < NUL
) else if %y% equ -1 (
   set operator1=+
   set operator2=*
   set /A x+=1
   set /P "=." < NUL
)

if %x% equ %cols% goto end

REM The algorithm for the pattern.

set /A "color=(x %operator1% y) %operator3% randa %operator1% (y %operator2% 2), f=color/16&15, b=color%%16"
set p[%y%,%x%]=!hstr:~%b%,1!!hstr:~%f%,1!

goto colorstart

:end
rem Show pattern points in color
echo/
set /A lines-=1, cols-=1
for /L %%y in (1,1,%lines%) do (
   set "line="
   for /L %%x in (0,1,%cols%) do (
      set line=!line! /!p[%%y,%%x]! %char%
   )
   ColorShow !line!
)

ECHO END   - %TIME% >> LOG.TXT

pause >nul
goto :EOF

I then used this Batch file to generate a 226 x 68 text screen via the same method I used in my Color Ascii Art program, and it took a little less than 8 minutes total. Here it is:

G20Ryd7.png

However, when I tried to generate the maximum screen size (449 x 136 text positions via Lucida console font @ size 5) the program takes too long because the number of variables required to store all screen points was too high and caused slow environment access. If the method could be modified to generate points in lines order (instead of columns order), this Batch file could be modified to run even faster.

Last edited by Aacini (29 Dec 2013 10:45)

Offline

#7 29 Dec 2013 12:08

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

I like yours Antonio.  The debug version is limited to the screen size but yours looks good at a large size.

This is a quick version with the original screen algorithm (using VBS for calculation).  It renders the image in only a few seconds.

It supports three command line switches:

/o for the original cell character
/r for a random cell character [default]
/mess for a random character in every cell

Save it all into a batch file and give it a go.


@echo off
:: use /o for original character, /r for a random character, /mess for a mess
if "%~1"=="" (set type=/r) else (set type=%~1)
set vbs="%temp%\Random art.vbs"
more +15 "%~f0" >%vbs%
:loop
set file="Random Colour Art - %random%.bat"
if exist %file% goto :loop
cscript /nologo %vbs% %file% %type%
del %vbs%
%file%
goto :EOF







  Const ForReading = 1, ForWriting = 2

  Set fso = CreateObject("Scripting.FileSystemObject")
  Set objArgs = WScript.Arguments

  outfile = objargs(0)

  Set f2 = fso.OpenTextFile(outfile, ForWriting, True)

  randomize

  randa=int((rnd*32768)/700)
  d=0
  x=0
  y=0
  op1="+"
  op2="*"
  op3="-"
  color=1
  if lcase(objargs(1))="/o" then pic=chr(34) & "°" & chr(34) ' original character
  if lcase(objargs(1))="/r" then pic=chr(34) & chr(Int((255 - 32 + 1) * Rnd + 32)) & chr(34) ' RANDOM character


  f2.writeline "@echo off"
  f2.writeline "mode con cols=80 lines=50"
  f2.writeline "("

 
  for c = 0 to 8192 step 2
  if not d = 0 then if d mod 128 = 0 then f2.writeline "echo Q)|Debug >nul": f2.writeline "("
  if op1 = "+" then y = y + 1
  if op1 = "-" then y = y - 1  
  if op3 = "-" then op3 = "+" else op3 = "-"
  if y = 50 then op1 = "-" : op2 = "+" : x = x + 1
  if y = -1 then op1 = "+" : op2 = "*" : x = x + 1
  if op1 = "+" then a1= x + y 
  if op1 = "-" then a1= x - y
  if op2 = "+" then a2= y + 2
  if op2 = "*" then a2= y * 2
  if op3 = "+" then if op1 = "+" then color = a1 + randa + a2
  if op3 = "-" then if op1 = "+" then color = a1 - randa + a2
  if op3 = "+" then if op1 = "-" then color = a1 + randa - a2
  if op3 = "-" then if op1 = "-" then color = a1 - randa - a2
  g = y * 160 + (x + 1 - 1) * 2
  hexa_2 = hex(abs(color))
  hexa = hex(g)
  if lcase(objargs(1))="/mess" then f2.writeline "echo eb800:" & hexa & " " & chr(34) & chr(Int((255 - 128 + 1) * Rnd + 128)) & chr(34) & " " & hexa_2 else f2.writeline "echo eb800:" & hexa & " " & pic & " " & hexa_2
  if x = 80 then exit for
  d = d + 1
  next

  f2.writeline "echo Q)|Debug >nul"
  f2.writeline "pause>nul"
  f2.Close

2yopwrm.jpg

Last edited by foxidrive (29 Dec 2013 12:18)

Offline

#8 29 Dec 2013 13:54

carlos
Member
From: Chile
Registered: 04 Nov 2008
Posts: 251
Website

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Hello. It takes code from Batch Paint v 1.3
And also this line:

Set /a "G=%Y% * 160 + (%X% + 1 - 1) * 2

can be optimized to:

Set /a "G=%Y% * 160 + %X% * 2

Last edited by carlos (29 Dec 2013 18:38)

Offline

#9 29 Dec 2013 15:13

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Yes carlos, the routine to calculate hex is there too. 
I saw the + 1 -1 and wondered if it was a typo and is something else was meant.

The color number routines generates negative numbers also - and the negative sign is ignored by the hex routine.

Offline

#10 29 Dec 2013 16:05

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Hi,

I like colors!

This example uses the findstr.exe color function. The colors shown is "flat unique" colors. Is not all the colors that we can display in dos batch windows. I have found about three hundred unique colors.

dq2ntu.png


The previus solutions with debug is impressive very fast! But there is a problem that on 64bit machine there isn't.

The solution with colorShow.exe of aacini is fast but the function uses assembly/machine language dependency and there no source code and no documentation.

The use of vbscript is good but with dos batch i thinks that is possible too at same speed. I'm right?

Another question:

Is possible in vbscript move cursor to a position (without debug of course!).

Thanks to all!

einstein1969

Offline

#11 29 Dec 2013 23:13

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

I modified my previous program into a Batch-JScript hybrid script, so the calculations are performed in the much faster JScript section and the display of the lines is completed in the Batch one. An aspect I like about JScript is that you may convert Batch code into JScript in a very similar way, so you may understand the converted section even if you know nothing about JScript.

@if (@CodeSection==@Batch) @then

@echo off
setlocal EnableDelayedExpansion

set /A randa=%random%/700, cols=0, lines=0
for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !lines! equ 0 ( set lines=%%a
   ) else if !cols! equ 0 ( set cols=%%a
   )
)
title Colors - %cols%x%lines%

:warning
cls
echo.
echo. Seed: %randa% (type 'seed' to change)
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art.     []
echo.                           []
echo.  Continue?
echo.                           ()
set choice=
set /p choice=(Y/N/seed):
if not defined choice goto :warning
if /i "%choice%"=="y" (cls&goto :colorstart)
if /i "%choice%"=="n" (cls&goto :eof)
if /i "%choice%"=="seed" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set /p randa=^>^>
  echo.
  echo. The seed has been changed.
  ping localhost -n 2 >nul
)
goto :warning

:colorstart

ECHO RANDA=%RANDA%, COLS=%COLS%, LINES=%LINES% > LOG.TXT
ECHO START @ %TIME% >> LOG.TXT

rem Batch section: Get lines generated by JScript section and show them with ColorShow.exe
for /F "delims=" %%a in ('Cscript //nologo //E:JScript "%~F0" %randa% %cols% %lines%') do ColorShow %%a

ECHO END   @ %TIME% >> LOG.TXT

pause >nul
goto :EOF

End of Batch section

@end

// JScript section: Calculate colors and generate output as parameters for ColorShow.exe auxiliary program

var x=0, y=0, randa=WScript.Arguments(0), cols=WScript.Arguments(1), lines=WScript.Arguments(2),
    operator1="+", operator2="*", operator3="-", plusminus=new Array(), char=176, p=new Array();

plusminus["+"]="-"; plusminus["-"]="+";
for ( var i=0; i <= lines; i++ ) p[i]=new Array();

while ( x < cols ) {

   y = eval("y"+operator1+"1");
   operator3 = plusminus[operator3];
   color = eval("(x"+operator1+"y)"+operator3+"randa"+operator1+"(y"+operator2+"2)");
   p[y][x] = (color&0xFF).toString(16);

   if (y == lines) {
      operator1="-";
      operator2="+";
      x+=1;
   } else if (y == 0) {
      operator1="+";
      operator2="*";
      x+=1;
   }

}

for ( y=1; y < lines; y++ ) {
   var line = "";
   for ( x=0; x < cols; x++ ) {
      line += " /"+p[y][x]+" "+char;
   }
   WScript.Echo(line);
}

Previous program took just 36 seconds to generate the Colors screen at the maximum possible resolution (in my computer) of 137 lines per 449 columns.

QJmYsLs.png

Offline

#12 30 Dec 2013 03:25

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

einstein1969 wrote:

Hi,

I like colors!

This example uses the findstr.exe color function. The colors shown is "flat unique" colors. Is not all the colors that we can display in dos batch windows. I have found about three hundred unique colors.

I like colors also! Did you seen my Color Ascii Art program? I tried to convert the black&white text representation generated by Ascgen2 program into a colored one, but in order to create an accurate color representation I need to control the pixels-to-text conversion. Also, I need a method to represent a range of colors (for example, 256) via the combination of certain characters with one color displayed over a different background one, but as I said in that topic: "With current Ascgen2 program, a good color conversion start with the font and characters used by Ascgen2 and particularly with Dither value that cause that colors be created by groups of characters, and continue with extensive testing and adjustment of the color codes assigned to each character. However, I have not time to do extensive tests, so I just defined a second color-codes table; if someone define a better one, please post it".

May I ask you for your method to generate the 300 unique colors?

einstein1969 wrote:

The solution with colorShow.exe of aacini is fast but the function uses assembly/machine language dependency and there no source code and no documentation.

einstein1969

Although the program is written in assembly language, you just need the .EXE executable file in order to use it (there is no such "assembly language dependency" thing). The documentation is in the ColorShow.exe program link, but I copied it from that site:

Show.exe description wrote:

Show characters from Ascii codes, string literals and Batch variables.

Show code[*times] | "literal" | variable[:[±]wide] ...

<code>, <times> and <wide> must be decimal numbers up to 255 each.

Times repeat the previous Ascii code character that number of times.
Wide define a width to show the variable value: justified at left, or justified at rigth if <wide> have minus sign, or centered if <wide> have plus sign.

At end, the number of displayed characters is returned in ERRORLEVEL.

ColorShow.exe description wrote:

Show characters in color.

ColorShow /bf showParam ...

/bf Specify a color attribute (see COLOR /? for more info)
showParam Specify the characters to show (see Show.exe program description)

ColorShow.exe show characters in the same way of Show.exe program, but in color.

Color attributes may be inserted at any place in the show parameters, setting the color
of following parameters. If the first show parameter has not a previous attribute, the
color of initial cursor position is used. Use / alone to indicate the color of initial
cursor position, use // to indicate the initial color attribute in reverse video.

At end, the original attribute of initial cursor position is returned in ERRORLEVEL.

You may insert an X-letter instead of an asterisk in CODE*TIMES parameter.

I think that assembly language source code is one of the less useful things for non assembly language programmers. As an example, this is the start of ColorShow.asm program:

        ;Initialize general values

        cld                             ;to increment indexes
        ;
        invoke  GetStdHandle, STD_OUTPUT_HANDLE ;EAX = console handle
        mov     hOutput, eax            ;store it
        ;                               ;get cursor position
        invoke  GetConsoleScreenBufferInfo, hOutput, ADDR csbInfo
        ;                               ;get attribute at cursor pos
        mov     ebx, csbInfo.dwCursorPosition
        invoke  ReadConsoleOutputAttribute, hOutput, ADDR wOrigAttrib, 1, ebx, ADDR bytesWritten
        ;
        mov     ax, wOrigAttrib         ;get original attribute
        mov     wAttribute, ax          ;initialize default attribute
        aam16                           ;separate Back- and Fore- ground colors
        xchg    al, ah                  ;exchange they
        aad16                           ;join they again
        mov     wOrigAttribRev, ax      ;and store it as "default reversed"
        ;
        lea     edi, outBuffer          ;EDI -> Output Buffer
        mov     lpOutBuffer, edi        ;store this address
        ;
        invoke  GetCmdLine              ;ESI -> Command Line
        ;
nextArg:

        ;Process next argument

        invoke  GetNextArg              ;ESI -> next arg
        mov     al, [esi]               ;load next char
        inc     esi                     ;and advance index
        ;
        test    al, al                  ;parameter ends?
        jz      endParam                ;yes: terminate

;;;;;;;;;

chkAttrib:
        cmp     al, '/'                 ;is /attrib?
        jne     chkQuote                ;no: continue testing
        ;
        sub     edi, lpOutBuffer        ;EDI = output buffer length
        jz      SHORT @F                ;buffer empty?: jump
        ;
        ;                               ;write this buffer with previous attrib
        invoke  WriteConsole_FillColor, hOutput, lpOutBuffer, edi, ADDR bytesWritten, 0
        ;
@@:
        mov     edi, lpOutBuffer        ;reset EDI -> start of buffer
        ;
        mov     al, [esi]               ;load next char
        inc     esi                     ;and advance index
        ;
        test    al, al                  ;parameter ends?
        jz      endParam                ;yes: terminate
        ;
        cmp     al, ' '                 ;is / only?
        jne     SHORT @F                ;no: continue
        ;
        mov     ax, wOrigAttrib         ;get original attribute
        mov     wAttribute, ax          ;set it as current attrib
        jmp     SHORT nextArg           ;and go back for next arg
        ;
@@:
        cmp     al, '/'                 ;is // ?
        jne     SHORT @F                ;no: continue
        ;
        mov     ax, wOrigAttribRev      ;get orig. attrib. reversed
        mov     wAttribute, ax          ;set it as current attrib
        jmp     SHORT nextArg           ;and go back for next arg
        ;
@@:

As I said before, you do not need the source code in order to use the executable file.

Offline

#13 30 Dec 2013 05:04

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

foxidrive wrote:

Thanks.  Yes, there is an issue when the screen size grows past 80 columns - I see that now.


The reason why it is so fast to display is purely due to the number of invocations of debug, and how many lines are processed at once.

In my top code, and the original too, change

set interval=23
to
set interval=256


and then when the generation is complete (or my top code) the picture will display very quickly from the created batch file.

The reason why I even had intervals at all was because I got an error saying that I put too many things into DEBUG at once, but perhaps I did something wrong.

Offline

#14 30 Dec 2013 05:20

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Aacini wrote:

I modified my previous program into a Batch-JScript hybrid script, so the calculations are performed in the much faster JScript section and the display of the lines is completed in the Batch one. An aspect I like about JScript is that you may convert Batch code into JScript in a very similar way, so you may understand the converted section even if you know nothing about JScript.

@if (@CodeSection==@Batch) @then

@echo off
setlocal EnableDelayedExpansion

set /A randa=%random%/700, cols=0, lines=0
for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !lines! equ 0 ( set lines=%%a
   ) else if !cols! equ 0 ( set cols=%%a
   )
)
title Colors - %cols%x%lines%

:warning
cls
echo.
echo. Seed: %randa% (type 'seed' to change)
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art.     []
echo.                           []
echo.  Continue?
echo.                           ()
set choice=
set /p choice=(Y/N/seed):
if not defined choice goto :warning
if /i "%choice%"=="y" (cls&goto :colorstart)
if /i "%choice%"=="n" (cls&goto :eof)
if /i "%choice%"=="seed" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set /p randa=^>^>
  echo.
  echo. The seed has been changed.
  ping localhost -n 2 >nul
)
goto :warning

:colorstart

ECHO RANDA=%RANDA%, COLS=%COLS%, LINES=%LINES% > LOG.TXT
ECHO START @ %TIME% >> LOG.TXT

rem Batch section: Get lines generated by JScript section and show them with ColorShow.exe
for /F "delims=" %%a in ('Cscript //nologo //E:JScript "%~F0" %randa% %cols% %lines%') do ColorShow %%a

ECHO END   @ %TIME% >> LOG.TXT

pause >nul
goto :EOF

End of Batch section

@end

// JScript section: Calculate colors and generate output as parameters for ColorShow.exe auxiliary program

var x=0, y=0, randa=WScript.Arguments(0), cols=WScript.Arguments(1), lines=WScript.Arguments(2),
    operator1="+", operator2="*", operator3="-", plusminus=new Array(), char=176, p=new Array();

plusminus["+"]="-"; plusminus["-"]="+";
for ( var i=0; i <= lines; i++ ) p[i]=new Array();

while ( x < cols ) {

   y = eval("y"+operator1+"1");
   operator3 = plusminus[operator3];
   color = eval("(x"+operator1+"y)"+operator3+"randa"+operator1+"(y"+operator2+"2)");
   p[y][x] = (color&0xFF).toString(16);

   if (y == lines) {
      operator1="-";
      operator2="+";
      x+=1;
   } else if (y == 0) {
      operator1="+";
      operator2="*";
      x+=1;
   }

}

for ( y=1; y < lines; y++ ) {
   var line = "";
   for ( x=0; x < cols; x++ ) {
      line += " /"+p[y][x]+" "+char;
   }
   WScript.Echo(line);
}

Previous program took just 36 seconds to generate the Colors screen at the maximum possible resolution (in my computer) of 137 lines per 449 columns.

http://i.imgur.com/QJmYsLs.png


...

...!??...

...how!??

These programs are f***ing amazing! You are all f***ing amazing! Not in my entire f***ing life would I be able to make these things the way you did!

Sure, it uses Colorshow.exe (external program), but hey, at least it's not DEBUG. I am going to go post downloads on my site, and put all this on my flash drive!

Thanks to all of you,

    Evan Theilig

Offline

#15 30 Dec 2013 11:09

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Aacini wrote:

I modified my previous program into a Batch-JScript hybrid script, so the calculations are performed in the much faster JScript section and the display of the lines is completed in the Batch one.

It seems that your code uses the lines figure from MODE CON but it can be the buffer setting.  It scrolls and scrolls here.

d:\>mode con

Status for device CON:
----------------------
    Lines:          999
    Columns:        100
    Keyboard rate:  31
    Keyboard delay: 0
    Code page:      850

Offline

#16 30 Dec 2013 16:59

AiroNG
Member
From: Germany
Registered: 26 Nov 2012
Posts: 42

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

@einstein1969
Wow! That looks amazing.
Is there a topic here or on dostipps that explains how to do this sort of thing with findstr.exe,
or could you post a codesnippet that i could study?

edit:
i mean: how do you make those color gradients?
From an earlier question of mine i was lead to carlos "Color function v20 patched" but with that one there seems to be no way to achieve the color gradients from your example

Last edited by AiroNG (30 Dec 2013 22:30)


I don't suffer from insanity, I enjoy every minute of it.

Offline

#17 30 Dec 2013 23:35

einstein1969
Member
From: Italy
Registered: 29 Dec 2013
Posts: 25

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

@aacini
I think you should post the full assembler code in order to give the possibility to expand / modify or rewrite the code for another ISA to others or for the future.

@AiroNg
Make a gradient is very simple. Aacini uses a simple gradient in http_//www.dostips.com/forum/viewtopic.php?p=15212#p15212

I post another simple gradient in http_//www.dostips.com/forum/viewtopic.php?p=28749#p28749

I often use the color21 of carlos or the color function of dbenham or the bare/minimal version of jeb. The debug.exe/colorShow.exe also should work for very fast execution.

@aacini
For the color palette: The method is not yet complete. I'm close to a simple solution. I'm started from the complex solution. ie measure the RGB component of every combination or color/character.

Sorry but i not have autorization to post link on this forum. substitute the _ with the right character.

I like this forum! smile

einstein1969

Offline

#18 30 Dec 2013 23:37

Aacini
Member
Registered: 05 Dec 2012
Posts: 149

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

foxidrive wrote:
Aacini wrote:

I modified my previous program into a Batch-JScript hybrid script, so the calculations are performed in the much faster JScript section and the display of the lines is completed in the Batch one.

It seems that your code uses the lines figure from MODE CON but it can be the buffer setting.  It scrolls and scrolls here.

d:\>mode con

Status for device CON:
----------------------
    Lines:          999
    Columns:        100
    Keyboard rate:  31
    Keyboard delay: 0
    Code page:      850

Yes. In Color Ascii Art post I explained that, in order to use the largest possible resolution for the text "images", you need to "make a copy of the short-cut icon of MS-DOS, right-click on it and select: Properties, Font tab and the smallest True-Type font: Lucida Console @ size 5; then Layout tab and the largest Width and Height for buffer and window size that not require scroll bars". If the purpose is to show large images, it have no sense to use the standard command-line window resolution and font; this means that the MS-DOS short-cut must be prepared in advance with the smallest font and the largest possible resolution (with the same values in the buffer size). After changed the font, you may easily set the largest possible resolution via this trick: execute WMIC, click on maximize window button and type EXIT.

Anyway, you just need to replace this section:

for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !lines! equ 0 ( set lines=%%a
   ) else if !cols! equ 0 ( set cols=%%a
   )
)

by this one:

set /A cols=80, lines=50
mode con cols=%cols% lines=%lines%

in order to set the resolution to any desired value.

Offline

#19 30 Dec 2013 23:55

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

Aacini wrote:

I modified my previous program into a Batch-JScript hybrid script, so the calculations are performed in the much faster JScript section and the display of the lines is completed in the Batch one. An aspect I like about JScript is that you may convert Batch code into JScript in a very similar way, so you may understand the converted section even if you know nothing about JScript.

@if (@CodeSection==@Batch) @then

@echo off
setlocal EnableDelayedExpansion

set /A randa=%random%/700, cols=0, lines=0
for /F "skip=2 tokens=2" %%a in ('mode con') do (
   if !lines! equ 0 ( set lines=%%a
   ) else if !cols! equ 0 ( set cols=%%a
   )
)
title Colors - %cols%x%lines%

:warning
cls
echo.
echo. Seed: %randa% (type 'seed' to change)
echo.                           []
echo.  This will take a while.  []
echo.  You cannot rush art.     []
echo.                           []
echo.  Continue?
echo.                           ()
set choice=
set /p choice=(Y/N/seed):
if not defined choice goto :warning
if /i "%choice%"=="y" (cls&goto :colorstart)
if /i "%choice%"=="n" (cls&goto :eof)
if /i "%choice%"=="seed" (
  echo.
  echo. What shall you change the seed to?
  echo.
  set /p randa=^>^>
  echo.
  echo. The seed has been changed.
  ping localhost -n 2 >nul
)
goto :warning

:colorstart

ECHO RANDA=%RANDA%, COLS=%COLS%, LINES=%LINES% > LOG.TXT
ECHO START @ %TIME% >> LOG.TXT

rem Batch section: Get lines generated by JScript section and show them with ColorShow.exe
for /F "delims=" %%a in ('Cscript //nologo //E:JScript "%~F0" %randa% %cols% %lines%') do ColorShow %%a

ECHO END   @ %TIME% >> LOG.TXT

pause >nul
goto :EOF

End of Batch section

@end

// JScript section: Calculate colors and generate output as parameters for ColorShow.exe auxiliary program

var x=0, y=0, randa=WScript.Arguments(0), cols=WScript.Arguments(1), lines=WScript.Arguments(2),
    operator1="+", operator2="*", operator3="-", plusminus=new Array(), char=176, p=new Array();

plusminus["+"]="-"; plusminus["-"]="+";
for ( var i=0; i <= lines; i++ ) p[i]=new Array();

while ( x < cols ) {

   y = eval("y"+operator1+"1");
   operator3 = plusminus[operator3];
   color = eval("(x"+operator1+"y)"+operator3+"randa"+operator1+"(y"+operator2+"2)");
   p[y][x] = (color&0xFF).toString(16);

   if (y == lines) {
      operator1="-";
      operator2="+";
      x+=1;
   } else if (y == 0) {
      operator1="+";
      operator2="*";
      x+=1;
   }

}

for ( y=1; y < lines; y++ ) {
   var line = "";
   for ( x=0; x < cols; x++ ) {
      line += " /"+p[y][x]+" "+char;
   }
   WScript.Echo(line);
}

Previous program took just 36 seconds to generate the Colors screen at the maximum possible resolution (in my computer) of 137 lines per 449 columns.

http://i.imgur.com/QJmYsLs.png


Try making this program with the following changes:

-Remove the prompt
-Make the colors go on forever, at least until a key is pressed
-Try to embed 'Colorshow.exe' into it, to (sort of) remove that dependency
-Compile the whole thing (maybe in Java) with no dependencies into an exe

This would be the most awesome thing you could do with colors. I didn't even know that this many posts would be on my topic. Not even this many posts are on Batch Paint v 1.3.

Best of luck (if you believe in that sort of thing),

    Evanator

Offline

#20 30 Dec 2013 23:57

Evanator
Member
Registered: 02 Aug 2013
Posts: 36

Re: [Batch Utility] Colors (Pattern-generator) by Evanator

foxidrive wrote:

Yes carlos, the routine to calculate hex is there too. 
I saw the + 1 -1 and wondered if it was a typo and is something else was meant.

The color number routines generates negative numbers also - and the negative sign is ignored by the hex routine.


I thought it meant something too, but I left it there just in case.

Offline

Board footer

Powered by