And now dos batch color secrets?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
IcarusLives
Posts: 117
Joined: 17 Jan 2016 23:55

Re: And now dos batch color secrets?

#16 Post by IcarusLives » 18 Apr 2016 22:39

I'm amazed by your colors, Einstein. I've been using this color function for my own personal use. I'm unsure if it is faster, but I'm sure it does not allow some colors like yours does.

Code: Select all

@echo off & setlocal enableDelayedExpansion
for /f %%a in ('"prompt $H&for %%b in (1) do rem"') do set "BS=%%a"

call :color CF "Hello" 0
call :color F9 " World" 1

call :color DE "Colors" 1

pause > nul & goto :eof


:color
set nL=%3
if not defined nL echo requires third argument & pause > nul & goto :eof
if %3 == 0 (
    <nul set /p ".=%bs%">%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
) else if %3 == 1 (
    echo %bs%>%2 & findstr /v /a:%1 /r "^$" %2 nul & del %2 2>&1 & goto :eof
)

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

Re: And now dos batch color secrets?

#17 Post by einstein1969 » 21 Apr 2016 08:26

Yes, this version of colors don't work. Seem that FINDSTR don't work if filename is on the range of EXTENDED ASCII chars.

IcarusLives
Posts: 117
Joined: 17 Jan 2016 23:55

Re: And now dos batch color secrets?

#18 Post by IcarusLives » 29 Apr 2018 21:57

Sorry to dig this up, but I thought maybe it might be useful to post a VT100 solution for WIN 10 PCs..

HSL
Image

Code: Select all

@echo off & setlocal enabledelayedexpansion

mode 90,60

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"

Set /a s=10000, v1=10000

For /L %%h in (0,15,360) do ( 
	For /L %%v in (10000,-400,0) do call :plot_HSL_RGB %%h !s! %%v
	if !v1! geq 0 (   <nul set /p "=%esc%[38;2;0;0;0mÛ"
		<nul set /p "=%esc%[38;2;0;0;0mÛ"
        For /L %%l in (0,8,360) do call :plot_HSL_RGB %%l !s! !v1!
        set /a v1=v1-500
	)
   echo(
)

pause
exit /b

:Plot_HSL_RGB H S L

	rem H=0..360 S=0..10000 L=0..10000

	set /a H=%1, S=%2, L=%3

	rem When 0 <= H < 360, 0 <= S <= 1 and 0 <= L <= 1:

	if !H! equ 360 set /a H=0

	if !H! lss 0 echo ERROR! & goto :EOF

	set /a va=2*L-10000
	if !va! lss 0 set /a va=-va

	set /a C=(10000-va)*S/10000

	set /a "h1=h*10000/60, mm = (h1 %% 20000) - 10000"

	if !mm! lss 0 set /a mm=-mm

	set /a X = C *(10000 - mm)/10000 , m = L - C/2

	rem (R,G,B) = (R'+m, G'+m, B'+m)

	if !H! lss 60 (set /a R=C+m, G=X+m, B=0+m) else (
	   if !H! lss 120 (set /a R=X+m, G=C+m, B=0+m) else (
		  if !H! lss 180 (set /a R=0+m, G=C+m, B=X+m) else (
			 if !H! lss 240 (set /a R=0+m, G=X+m, B=C+m) else (
				if !H! lss 300 (set /a R=X+m, G=0+m, B=C+m) else (
				   if !H! lss 360 (set /a R=C+m, G=0+m, B=X+m) else (echo ERROR!)
				)
			 )
		  )
	   )
	)

	set /a R=R*255/10000, G=G*255/10000, B=B*255/10000

	<nul set /p "=%esc%[38;2;!R!;!G!;!B!mÛ"

goto :eof
HSV
Image

Code: Select all

@echo off & setlocal enabledelayedexpansion

mode 90,60

for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"

Set /a s=10000, v1=10000

For /L %%h in (0,15,360) do ( 
	For /L %%v in (10000,-400,0) do call :plot_HSV_RGB %%h !s! %%v
	if !v1! geq 0 (   <nul set /p "=%esc%[38;2;0;0;0mÛ"
		<nul set /p "=%esc%[38;2;0;0;0mÛ"
        For /L %%l in (0,8,360) do call :plot_HSV_RGB %%l !s! !v1!
        set /a v1=v1-500
	)
   echo(
)

pause
exit /b

:::::::::::::::::::::::::::::::::::::::::::
:Plot_HSV_RGB H S V
	rem H=0..360 S=0..10000 V=0..10000

	set /a H=%1, S=%2, V=%3

	rem When 0 <= H < 360, 0 <= S <= 1 and 0 <= V <= 1:

	if !H! equ 360 set /a H=0

	if !H! lss 0 echo ERROR! & goto :EOF

	set /a "h1=h*10000/60, mm = (h1 %% 20000) - 10000"

	if !mm! lss 0 set /a mm=-mm

	set /a C = (V * S) / 10000

	set /a "X = C *(10000 - mm)/10000 , m = V - C"

	rem (R,G,B) = (R'+m, G'+m, B'+m)

	if !H! lss 60 (set /a R=C+m, G=X+m, B=0+m) else (
	   if !H! lss 120 (set /a R=X+m, G=C+m, B=0+m) else (
		  if !H! lss 180 (set /a R=0+m, G=C+m, B=X+m) else (
			 if !H! lss 240 (set /a R=0+m, G=X+m, B=C+m) else (
				if !H! lss 300 (set /a R=X+m, G=0+m, B=C+m) else (
				   if !H! lss 360 (set /a R=C+m, G=0+m, B=X+m) else (echo ERROR!)
	)))))

	set /a "R=R*255/10000, G=G*255/10000, B=B*255/10000"

	<nul set /p "=%esc%[38;2;!R!;!G!;!B!mÛ"
exit /b

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

Re: And now dos batch color secrets?

#19 Post by einstein1969 » 03 May 2018 10:08

Hi Icarus,

This is great result!!!

Einstein1969

IcarusLives
Posts: 117
Joined: 17 Jan 2016 23:55

Re: And now dos batch color secrets?

#20 Post by IcarusLives » 03 May 2018 13:14

Einstein, my friend, where have you been? Your work on colors has inspired me over time.

Post Reply