And now dos batch color secrets?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
IcarusLives
Posts: 175
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: 960
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: 175
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: 960
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: 175
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.

SharaStar
Posts: 2
Joined: 23 Oct 2020 14:17

Re: And now dos batch color secrets?

#21 Post by SharaStar » 27 Oct 2020 14:40

Thank you, this is what Im looking for related to this post viewtopic.php?p=63146#p63146 question. Just need to add the color.

This can print images as if it is pixel shades right?

I dont know how pixel programming or graphic programming and someone suggested to learn using consoles or shells, I dont know where to find resources on how to get it done.

I hope to access the video1 and video2 or hardware layer of graphic card and monitor screen display to get the pixel address manually if thats the way to render the fastest image on screen without too many layers inbetween.

However the consoles or shells are the beginning to gain that level of skills so i start here in Batch.

I have no access to any IDE. So am stuck with Batch programming only for now. Again Thank you for the code snippets tutorial <3 :D
einstein1969 wrote:
12 Dec 2015 07:35
Hi to all,

This is my old project for draw a sphere on console using the trick of font Lucida Console size 5 and the "shadow" chars
and the findstr colour mode.

I use an external MATH until a dos batch MATH is not avaible. The SQRT is ready. Lack the EXP/POW at the moments. But my goal is do in "native/pure" mode.

I need discovery a mechanism for create RIGHT colors on console and on image file ( I have open a separated thread )

Antialiasing and dithering ,small fonts usage and unicode use are other goals.

I hope that you can contribute to this work. TIA

Yuo can port in HTA for best view. See Aacini works!

results:
Image

- Use Lucida console font 5
- Disable ClearType
- Enable "Smooth Edges of Screen Fonts"

code:

Code: Select all

@echo off & setlocal EnableDelayedExpansion

rem Use Lucida Console font size 5

rem Version 2.0.9.2 dec-2015
rem by einstein1969
rem http://rosettacode.org/wiki/Draw_a_sphere

mode 90,70 
color 0f
pushd "%TMP%"

if not exist FPU-Module.js echo WScript.Stdout.WriteLine(eval(WScript.Stdin.ReadLine().replace(/\x22/g,"")));> FPU-Module.js
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (set "DEL=%%a")
<nul set /p ".=%DEL%%DEL%%DEL%%DEL%%DEL%%DEL%" > "'"

set "color1=778707880880880000000034"
set "color2=FFFFFFF7F7F7777F88788043"
set   "char=Û²²±²°±Û±²°²±°±°Û²°±°  "
set numshadesH=23

set "light[0]=30"
set "light[1]=30"
set "light[2]=-50"

call :normalize2 light

<nul set/p "=%DEL%   °"
call :draw_sphereH2 8 3.5 0.20
call :draw_sphereH2 8 1.5 0.10
call :draw_sphereH2 8 3.5 0.10
call :draw_sphereH2 8 32.0 0.05

del $$$.color.txt
del '

popd

pause

goto :eof

:::::::::::::::::::::::::::::::::::::::::::::::::
:draw_sphereH2 raggio k ambiente

set R=%1
set k=%2
set ambiente=%3

call :calculate2 "Math.floor(-!R!)" floorI
call :calculate2 "Math.ceil(!R!)" CeilI

For /L %%i in (!floorI!,1,!CeilI!) do (

  call :calculate2 "%%i+0.5" x
  call :calculate2 "Math.floor(-2*!R!)" floorJ
  call :calculate2 "Math.ceil(2*!R!)" CeilJ

  For /L %%j in (!floorJ!,1,!ceilJ!) do (

    rem for aspect ratio "(%%j/2+0.5)" = y
    call :calculate2 "!x!*!x! + (%%j/2+0.5)*(%%j/2+0.5) - !R!*!R!" inS

    if "!inS:~0,1!"=="-" (

      call :calculate2 "Math.round( (1 - (Math.pow(Math.max(0,-(!light[0]!*(!x!/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! -(!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))))+(!light[1]!)*((%%j/2+0.5)/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))))+(!light[2]!)*(Math.sqrt(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5)))/Math.sqrt(!x!*!x!+(%%j/2+0.5)*(%%j/2+0.5)+(!R! * !R! - (!x! * !x!) - ((%%j/2+0.5) * (%%j/2+0.5))))))),!k!)+!ambiente!)) * (!numshadesH! - 1) )" intensity
      if "!intensity:~0,1!"=="-" set intensity=0
      if !intensity! geq !numshadesH! set /a intensity=!numshadesH!-1

      title !intensity!
      for %%s in (!intensity!) do call :shadow %%s

    ) else (<nul set/p "=.%DEL%°")

  )

  echo(°
  <nul set/p "=%DEL%   °"
)

goto :eof

::::::::::::::::::::::::::::::::::::::::::::::
:calculate2 expr retvar
  echo "%~1" >%TMP%\in.txt
  Cscript //nologo FPU-Module.js <%TMP%\in.txt >%TMP%\out.txt
  set /p "%2=" <%TMP%\out.txt
  set "%2=!%2:,=.!"
goto :eof

::::::::::::::::::::::::::::::::::::::::::::::::
:normalize2

  set _0=!%1[0]!
  set _1=!%1[1]!
  set _2=!%1[2]!

  call :calculate2 "!_0!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[0]
  call :calculate2 "!_1!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[1]
  call :calculate2 "!_2!/Math.sqrt(!_0!*!_0!+!_1!*!_1!+!_2!*!_2!)" %1[2]
	
goto :eof

:::::::::::::::::::::::::::::::::::::::::::::::::
:shadow

    (echo !char:~%1,1!\..\'
    ) > $$$.color.txt && findstr /a:!color1:~%1,1!!color2:~%1,1! /f:$$$.color.txt "."

goto :eof
einstein1969

Post Reply