set /a "x=r1 * !sin(x):x=angle!"
set /a "y=r2 * !cos(x):x=angle!"
set /a "%translate%"
call :plot x y .
call :showCanvas
REM call :updateCanvas
goto :main
:mathMacros
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)=( M=(N), x=M/(11*1024)+40, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x+=((M-x*x)>>31)/(1+((N)>>31)) )"
set "Abs(x)=(((x)>>31|1)*(x))"
set "swap(x,y)=t=x, x=y, y=t"
set "translate=x+=width / 2, y+=height / 2"
goto :eof
:canvas
set /a "width=%~1 - 1", "height=%~2 - 1", "conWidth=width + 5", "conHeight=height + 6", "_=0"
for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
call :updateCanvas
call :cursorpos
if exist "%temp%\cursorpos.exe" ( set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
mode con: cols=%conWidth% lines=%conHeight%
goto :eof
:updateCanvas
for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
goto :eof
:showCanvas
%cls%
echo= %outerBuffer%
for /l %%a in (0,1,%height%) do echo= #!_[%%a]!#
echo= %outerBuffer%
if "%~1" equ "/u" for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
goto :eof
goto :eof
:plot x y
setlocal
set /a "_y=%~2", "_x=%~1", "_x2=%~1 + 1"
(endlocal
set "_[%_y%]=!_[%_y%]:~0,%_x%!%~3!_[%_y%]:~%_x2%!"
)
goto :eof
Follow along with me! (everything you need code with me) Spoiler (Click to View)
Code
@echo off & setlocal enableDelayedExpansion
call :canvas 50 40
call :mathMacros
:main
call :showCanvas
call :updateCanvas
goto :main
:mathMacros
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)=( M=(N), x=M/(11*1024)+40, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x=(M/x+x)>>1, x+=((M-x*x)>>31)/(1+((N)>>31)) )"
set "Abs(x)=(((x)>>31|1)*(x))"
set "swap(x,y)=t=x, x=y, y=t"
set "translate=x+=width / 2, y+=height / 2"
goto :eof
:canvas
set /a "width=%~1 - 1", "height=%~2 - 1", "conWidth=width + 5", "conHeight=height + 6", "_=0"
for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
call :updateCanvas
call :cursorpos
if exist "%temp%\cursorpos.exe" ( set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
mode con: cols=%conWidth% lines=%conHeight%
goto :eof
:updateCanvas
for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
goto :eof
:showCanvas
%cls%
echo= %outerBuffer%
for /l %%a in (0,1,%height%) do echo= #!_[%%a]!#
echo= %outerBuffer%
if "%~1" equ "/u" for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
goto :eof
goto :eof
:plot x y
setlocal
set /a "_y=%~2", "_x=%~1", "_x2=%~1 + 1"
(endlocal
set "_[%_y%]=!_[%_y%]:~0,%_x%!%~3!_[%_y%]:~%_x2%!"
)
goto :eof