Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- setlocal enableDelayedExpansion
- @call :canvas 50 50
- call :mathMacros
- rem Experiment with this number
- set "k=7"
- rem This draws the flower :)
- rem ---------------------------------------------------------------------------
- for /l %%a in (0,1,400) do (
- set /a "r=2000 * !sin(x):x= PI_div_2 - (k * %%a) * PI / 180! / 100000"
- set /a "y=r * !sin(x):x= PI_div_2 - %%a * PI / 180! / 100000"
- set /a "x=r * !sin(x):x= %%a * PI / 180! / 100000"
- set /a "x+=translateX"
- set /a "y+=translateY"
- %checkBounds% call :plot !x! !y!
- call :showCanvas
- )
- pause & exit
- rem ---------------------------------------------------------------------------
- :canvas
- @echo off
- set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
- if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
- for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call :updateCanvas
- mode con: cols=%conWidth% lines=%conHeight%
- goto :eof
- :updateCanvas
- for /l %%a in (0,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
- set "_="
- goto :eof
- :showCanvas
- %cls%
- echo=%outerBuffer%
- for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
- echo=%outerBuffer%
- goto :eof
- goto :eof
- :plot x y
- setlocal
- set /a "_x2=%~1 + 1"
- (endlocal
- set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
- )
- goto :eof
- :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)%%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%)"
- set "_SIN="
- set /a "translateX=width / 2"
- set /a "translateY=height / 2"
- set "swap(x,y)=t=x, x=y, y=t"
- set "checkBounds=if ^!x^! leq %width% if ^!y^! leq %height% if ^!x^! geq 0 if ^!y^! geq 0"
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement