I am always really shy posting things here..

So lately I have been experimenting with WINDOWS 10 VT100 escape sequences. This allows me to place characters throughout the console in any color I want....

So I have produced a number of macros; plot, circle, line, and arc. So far, only plot and circle take color arguments, but I'll implement shortly. For now, you can color with plot and circle, but line and arc remain at 30/255 in terms of colour.

This is a little flickery.... but hey, it's pure batch!

le code

Code: Select all

```
@echo off & setlocal enableDelayedExpansion
mode 50,50
set ^"LF=^
^" Above empty line is required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3 delims=:" %%1 in ("^!args^!:^!ESC^!") do (%\n%
for /f "tokens=1-4" %%a in ("%%~1") do ^<nul set /p "=%%3[%%b;%%aH%%3[38;5;%%cm%%3[48;5;%%dm%%~2%%3[0m"%\n%
)) else set args=
set circle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-6" %%1 in ("^!args^!") do (%\n%
if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
for /l %%y in (-%%3,1,%%3) do for /l %%x in (-%%3,1,%%3) do (%\n%
set /a "S=(%%x * %%x) + (%%y * %%y) - (%%3 * %%3)", "_3div2=%%3 / 2", "tx=%%x+%%1", "ty=%%y+%%2"%\n%
for /f "tokens=1-5" %%a in ("^!S^! ^!_3div2^! ^!tx^! ^!ty^! ^!hue^!") do (%\n%
if "%%6" equ "/f" ( if %%a leq 1 ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
) else if "%%6" equ "/n" ( if %%a geq -%%3 ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
) else if %%a geq -%%3 if %%a leq %%b ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
))%\n%
set "s="%\n%
)) else set args=
for /l %%b in (0,1,4) do (
set /a "x%%b=!random! %% 40 + 10"
set /a "y%%b=!random! %% 40 + 10"
set /a "i%%b=!random! %% 3 + 1"
set /a "j%%b=!random! %% 2 + 1"
set /a "s%%b=!random! %% 3 + 2"
set /a "b%%b=50 - s%%b"
set /a "c%%b=!random! %% 255"
)
for /l %%# in () do ( for /l %%b in (0,1,4) do (
set /a "x%%b+=i%%b", "y%%b+=j%%b"
if !x%%b! geq !b%%b! set /a "x%%b=b%%b", "i%%b*=-1"
if !y%%b! geq !b%%b! set /a "y%%b=b%%b", "j%%b*=-1"
if !x%%b! leq !s%%b! set /a "x%%b=s%%b", "i%%b*=-1"
if !y%%b! leq !s%%b! set /a "y%%b=s%%b", "j%%b*=-1"
%circle% !x%%b! !y%%b! !s%%b! . !c%%b!
)
cls
)
```

Code: Select all

```
:macros
set ^"LF=^
^" Above empty line is required - do not remove
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3 delims=:" %%1 in ("^!args^!:^!ESC^!") do (%\n%
for /f "tokens=1-4" %%a in ("%%~1") do ^<nul set /p "=%%3[%%b;%%aH%%3[38;5;%%cm%%3[48;5;%%dm%%~2%%3[0m"%\n%
)) else set args=
set circle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-6" %%1 in ("^!args^!") do (%\n%
if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
for /l %%y in (-%%3,1,%%3) do for /l %%x in (-%%3,1,%%3) do (%\n%
set /a "S=(%%x * %%x) + (%%y * %%y) - (%%3 * %%3)", "_3div2=%%3 / 2", "tx=%%x+%%1", "ty=%%y+%%2"%\n%
for /f "tokens=1-5" %%a in ("^!S^! ^!_3div2^! ^!tx^! ^!ty^! ^!hue^!") do (%\n%
if "%%6" equ "/f" ( if %%a leq 1 ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
) else if "%%6" equ "/n" ( if %%a geq -%%3 ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
) else if %%a geq -%%3 if %%a leq %%b ( ^!plot^! %%c %%d %%e 0 :%%~4)%\n%
))%\n%
set "s="%\n%
)) else set args=
set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
set /a "x0=%%~1", "y0=%%~2", "x1=%%~3", "y1=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
for /f "tokens=1-2" %%6 in ("^!dx^! ^!dy^!") do (%\n%
if %%~7 lss 0 ( set /a "dy=-%%~7", "stepy=-1" ) else ( set "stepy=1" )%\n%
if %%~6 lss 0 ( set /a "dx=-%%~6", "stepx=-1" ) else ( set "stepx=1" )%\n%
set /a "dx<<=1", "dy<<=1"%\n%
)%\n%
for /f "tokens=1-8" %%a in ("^!dx^! ^!dy^! ^!x0^! ^!x1^! ^!y0^! ^!y1^! ^!stepx^! ^!stepy^!") do (%\n%
if %%~a gtr %%~b (%\n%
set /a "fraction=%%~b - (%%~a >> 1)"%\n%
for /l %%x in (%%~c,%%~g,%%~d) do (%\n%
for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "y0+=%%~h", "fraction-=%%~a"%\n%
set /a "fraction+=%%~b"%\n%
for /f "tokens=1" %%6 in ("^!y0^!") do (%\n%
if 0 leq %%x if %%x lss 199 if 0 leq %%~6 if %%~6 lss 199 ^!plot^! %%x %%~6 30 0 :%%~5%\n%
)%\n%
)%\n%
) else (%\n%
set /a "fraction=%%~a - (%%~b >> 1)"%\n%
for /l %%y in (%%~e,%%~h,%%~f) do (%\n%
for /f "tokens=1" %%6 in ("^!fraction^!") do if %%~6 geq 0 set /a "x0+=%%~g", "fraction-=%%~b"%\n%
set /a "fraction+=%%~a"%\n%
for /f "tokens=1" %%6 in ("^!x0^!") do (%\n%
if 0 leq %%~6 if %%~6 lss 199 if 0 leq %%y if %%y lss 199 ^!plot^! %%~6 %%y 30 0 :%%~5%\n%
)%\n%
)%\n%
)%\n%
)%\n%
)) else set args=
set arc=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-6" %%a in ("^!args^!") do (%\n%
set /a "arc=%%~d + %%~f"%\n%
for /f "tokens=1-3" %%g in ("^!arc^! sin^(x^) cos^(x^)") do for /l %%j in (%%~f,%%~e,%%~g) do (%\n%
set /a "_x=%%~c * ^!%%~h:x=%%~j^! + %%~a", "_y=%%~c * ^!%%~i:x=%%~j^! + %%~b"%\n%
for /f "tokens=1,2" %%X in ("^!_x^! ^!_y^!") do ^!line^! %%~a %%~b %%~X %%~Y .%\n%
)%\n%
)) else set args=
set /a "PI=(35500000/113+5)/10, PI_div_2=(35500000/113/2+5)/10, PIx2=2*PI, PI32=PI+PI_div_2"
set "_SIN=a-a*a/1920*a/312500+a*a/1920*a/15625*a/15625*a/2560000-a*a/1875*a/15360*a/15625*a/15625*a/16000*a/44800000"
set "SIN(x)=(a=(x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%) / 10000"
set "COS(x)=(a=(15708 - x * 31416 / 180)%%62832, c=(a>>31|1)*a, a-=(((c-47125)>>31)+1)*((a>>31|1)*62832) + (-((c-47125)>>31))*( (((c-15709)>>31)+1)*(-(a>>31|1)*31416+2*a) ), %_SIN%) / 10000"
set "_SIN="
set "Sqrt(N)=( x=(N)/(11*1024)+40, x=((N)/x+x)/2, x=((N)/x+x)/2, x=((N)/x+x)/2, x=((N)/x+x)/2, x=((N)/x+x)/2 )"
set "Sign(n)=(n>>31)|((-n>>31)&1)"
set "Abs(x)=(((x)>>31|1)*(x))"
REM Max1(x)= if (x geq y) then x else y
set "Max(x)=( ?=((x-y)>>31)+1, ?*x + ^^^!?*y )"
set "Max=( ?=(((((t1)>>31|1)*(t1))-(((t2)>>31|1)*(t2)))>>31)+1, ?*(2*(((t1)>>31|1)*(t1))-(((t2)>>31|1)*(t2))-((((t1)>>31|1)*(t1))-(((t2)>>31|1)*(t2)))) + ^^^!?*((((t1)>>31|1)*(t1))-(((t2)>>31|1)*(t2))-((((t1)>>31|1)*(t1))-(((t2)>>31|1)*(t2))*2)) )"
set "getDistance(x2,x1,y2,y1)=( @=x2-x1, $=y2-y1, ?=(((@>>31|1)*@-(($>>31|1)*$))>>31)+1, ?*(2*(@>>31|1)*@-($>>31|1)*$-((@>>31|1)*@-($>>31|1)*$)) + ^^^!?*((@>>31|1)*@-($>>31|1)*$-((@>>31|1)*@-($>>31|1)*$*2)) )"
set "swap(x,y)=t=x, x=y, y=t"
goto :eof
```