Advertisement
IcarusLives

Rose pedal algorithm

Mar 8th, 2017
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.24 KB | None | 0 0
  1. setlocal enableDelayedExpansion
  2. @call :canvas 50 50
  3.  
  4. call :mathMacros
  5.  
  6. rem Experiment with this number
  7. set "k=7"
  8.  
  9. rem This draws the flower :)
  10. rem ---------------------------------------------------------------------------
  11. for /l %%a in (0,1,400) do (
  12.  
  13.     set /a "r=2000 * !sin(x):x= PI_div_2 - (k * %%a) * PI / 180! / 100000"
  14.     set /a "y=r *    !sin(x):x= PI_div_2 -      %%a  * PI / 180! / 100000"
  15.     set /a "x=r *    !sin(x):x=                 %%a  * PI / 180! / 100000"
  16.  
  17.     set /a "x+=translateX"
  18.     set /a "y+=translateY"
  19.  
  20.     %checkBounds% call :plot !x! !y!
  21.     call :showCanvas
  22. )
  23. pause & exit
  24. rem ---------------------------------------------------------------------------
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32. :canvas
  33.     @echo off
  34.         set /a "width=%~1 - 1", "height=%~2 - 1", "_=-1", "conWidth=width + 4", "conHeight=height + 5"
  35.         if exist cursorpos.exe ( set "cls=cursorpos 0 0" ) else ( set "cls=cls" )
  36.         for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
  37.         for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  38.         call :updateCanvas
  39.         mode con: cols=%conWidth% lines=%conHeight%
  40.     goto :eof
  41.    
  42.     :updateCanvas
  43.         for /l %%a in (0,1,%height%) do set /a "_+=1" & set "_[!_!]=%widthBuffer%"
  44.         set "_="
  45.     goto :eof
  46.    
  47.     :showCanvas
  48.         %cls%
  49.         echo=%outerBuffer%
  50.         for /l %%a in (0,1,%height%) do echo=#!_[%%a]!#
  51.         echo=%outerBuffer%
  52.     goto :eof
  53. goto :eof
  54.  
  55.  
  56.  
  57. :plot x y
  58.     setlocal
  59.         set /a "_x2=%~1 + 1"
  60.         (endlocal
  61.             set "_[%~2]=!_[%~2]:~0,%~1!.!_[%~2]:~%_x2%!"
  62.         )
  63. goto :eof
  64.  
  65.  
  66.  
  67. :mathMacros
  68.     set /a "PI=(35500000/113+5)/10, PI_div_2=(35500000/113/2+5)/10, PIx2=2*PI, PI32=PI+PI_div_2"
  69.     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"
  70.     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%)"
  71.     set "_SIN="
  72.     set /a "translateX=width / 2"
  73.     set /a "translateY=height / 2"
  74.     set "swap(x,y)=t=x, x=y, y=t"
  75.     set "checkBounds=if ^!x^! leq %width% if ^!y^! leq %height% if ^!x^! geq 0 if ^!y^! geq 0"
  76. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement