0

I want to make a batch file which outputs art in rainbow style.

I used this code as a base: https://gist.github.com/ChanSec/10519942

I read somewhere that I can output art by insterting a .txt file (but I don't want more files), so I came to this:

:::Something
:::art stuff
:::More
for /f "delims=: tokens=*" %%A in ('findstr /b ::: "%~f0"') do @echo(%%A

This is my code:http://pastebin.com/ZHw2QAXM

Every time I launch it, it spams the whole screen and only shows the color in red (only the art RED should be in color red, the HELLO art should switch colors)

How can I make it stop spamming (the art should be visible only once and switch colors) and fix the colors? Besides that, is there an easy way to change the 2 in this line: ping -n 2 127.0.0.1 > nul with an integer that I can change so I don't have to change it on every single line? I'm not familiar with batch coding.

1

1 Answer 1

1

You could try something like this:

@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
:loop
FOR %%G IN (9,a,b,c,d,e) DO (
::[HELLO
::[WORLD
::]RED
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :ColorText 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :ColorText 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
echo.
goto :eof

Credits to NiklasJ for this post about coloring per line in batch. Note that you can't however, use the following special characters

. | ! % ; : [ ] ) / \ < > % ^ * ? "

in the text to display.

This echoes all the lines after ::[ with changing colors, and after ::] in red.

EDIT

So I took a shot at it again, this time using the code used by Jeb in this post, and here is the updated version. It still can't handle all characters, but it seems this one is only limited to not being able to handle

: / \

@echo off
set "timeout=2"
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


:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :color 0%%G "%%A"
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :color 0c "%%A"
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b

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

::[  _    _      _ _      
::[ | |  | |    | | |      
::[ | |__| |____| | | ___  
::[ |  __  |  _ | | || _ |
::[ | |  | |  __| | | (_) |
::[ |_|  |_|____|_|_||___|
::[    
::]   _____          _
::]  |  __ |        | |
::]  | |__) |___  __| |
::]  |  _  || _ || _` |
::]  | | | |  __| (_| |
::]  |_|  |_|___||__,_|

EDIT #2 Finally, after experimenting with some other code by dbenham in this answer, it seems this is the only version that really supports all your character, although it doesn't like blank lines and is much slower:

@echo off
setlocal EnableDelayedExpansion
set "timeout=2"
set q=^"

:loop
FOR %%G IN (9,a,b,c,d,e) DO (
cls
for /f "delims=:[ tokens=*" %%A in ('findstr /b "::[" "%~f0"') do @call :c 0%%G "%%A" /n
for /f "delims=:] tokens=*" %%A in ('findstr /b "::]" "%~f0"') do @call :c 0c "%%A" /n
ping -n !timeout! 127.0.0.1 > nul
)
goto loop
exit /b

:c
setlocal enableDelayedExpansion
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:colorPrint Color  Str  [/n]
setlocal
set "s=%~2"
call :colorPrintVar %1 s %3
exit /b

:colorPrintVar  Color  StrVar  [/n]
if not defined DEL call :initColorPrint
setlocal enableDelayedExpansion
pushd .
':
cd \
set "s=!%~2!"
:: The single blank line within the following IN() clause is critical - DO NOT REMOVE
for %%n in (^"^

^") do (
  set "s=!s:\=%%~n\%%~n!"
  set "s=!s:/=%%~n/%%~n!"
  set "s=!s::=%%~n:%%~n!"
)
for /f delims^=^ eol^= %%s in ("!s!") do (
  if "!" equ "" setlocal disableDelayedExpansion
  if %%s==\ (
    findstr /a:%~1 "." "\'" nul
    <nul set /p "=%DEL%%DEL%%DEL%"
  ) else if %%s==/ (
    findstr /a:%~1 "." "/.\'" nul
    <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%"
  ) else (
    >colorPrint.txt (echo %%s\..\')
    findstr /a:%~1 /f:colorPrint.txt "."
    <nul set /p "=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%"
  )
)
if /i "%~3"=="/n" echo(
popd
exit /b


:initColorPrint
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "DEL=%%A %%A"
<nul >"%temp%\'" set /p "=."
subst ': "%temp%" >nul
exit /b


:cleanupColorPrint
2>nul del "%temp%\'"
2>nul del "%temp%\colorPrint.txt"
>nul subst ': /d
exit /b

::[  _    _      _ _      
::[ | |  | |    | | |      
::[ | |__| | ___| | | ___  
::[ |  __  |/ _ \ | |/ _ \
::[ | |  | |  __/ | | (_) |
::[ |_|  |_|\___|_|_|\___/
::]   _____          _
::]  |  __ \        | |
::]  | |__) |___  __| |
::]  |  _  // _ \/ _` |
::]  | | \ \  __/ (_| |
::]  |_|  \_\___|\__,_|
9
  • Thank you for the answer, but this is not exactly what I want. I want to do that rainbow style on ASCII art. Is that possible? Jan 26, 2016 at 20:20
  • @FPSUsername What is exactly different from what you want? If you want to use any of the forbidden characters in your ascii art, I suggest taking a look at the answer recommended by @rojo, which contains more information about that. Jan 26, 2016 at 23:22
  • Somehow, his script doesn't work on my pc. It opens, then closes cmd (it prints very fast). It is something like that, except I want the art to change its color every second. Jan 27, 2016 at 17:36
  • Okay, I finally managed to get close to what I want: pastebin.com/wyf7WGqq The Hello art changes colors like I want to, but the RED part doesn't stay red (obviously as it is coded like that). I have to color a piece of the text and leave the RED part with a red color, yet I want to try and make the RED art go from red to white and back to red (continiously) Jan 27, 2016 at 18:24
  • @FPSUsername please look at the two edits of the updated answer Jan 27, 2016 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.