Advertisement
Guest User

Untitled

a guest
Jun 13th, 2018
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. REM INITIALIZE -----------------------------------------------------------------------------
  4. call :macros
  5.  
  6. rem initialize SCREEN 0
  7. set /a "hei=wid=90", "heixwid=hei*wid"
  8. mode con: cols=%wid% lines=%hei%
  9. for /l %%a in (0,1,%heixwid%) do set "updateScreen0=!updateScreen0! "
  10. set "screen0=%updateScreen0%"
  11.  
  12. :: define x and y
  13. set /a "x=!random! %% 90 + 1", "y=!random! %% 90 + 1"
  14. set /a "i=!random! %% 3 + 1", "j=!random! %% 2 + 1"
  15. REM ----------------------------------------------------------------------------------------
  16.  
  17.  
  18. rem infinite loop---------------------------------------------------------------------------
  19. for /l %%# in () do (
  20.  
  21. rem calculate frame, xyFrame, and hue
  22. set /a "frame+=1", "xyFrame+=5", "hue=(frame %% 256) + 16"
  23.  
  24. rem calculate path of fidget spinner
  25. set /a "x=20 * !cos(x):x=xyFrame! + 45", "y=20 * !sin(x):x=xyFrame! + 45"
  26.  
  27. rem calculate position of each ball around CENTER ball
  28. set /a "fr000+=20", "fr120=fr000 + 90", "fr240=fr120 + 90", "fr360=fr240 + 90"
  29. set /a "rx0=8 * !cos(x):x=fr000! + x", "ry0=8 * !sin(x):x=fr000! + y"
  30. set /a "rx1=8 * !cos(x):x=fr120! + x", "ry1=8 * !sin(x):x=fr120! + y"
  31. set /a "rx2=8 * !cos(x):x=fr240! + x", "ry2=8 * !sin(x):x=fr240! + y"
  32. set /a "rx3=8 * !cos(x):x=fr360! + x", "ry3=8 * !sin(x):x=fr360! + y"
  33.  
  34. rem draw our circle on SCREEN 0
  35. for /l %%a in (0,1,3) do (
  36. rem cc = circle color - give each ball a color 16-256
  37. set /a "cc=(%%a + 1) * ((%%a + 2) * (%%a + 1)) %% 256 + 16"
  38. rem ultilize Line 27-32 to position/draw each ball
  39. %fastCircle% !rx%%a! !ry%%a! 3 3 !cc! 0
  40. )
  41.  
  42. rem draw our sprite on SCREEN 1
  43. %fastCircle% !x! !y! 2 2 !hue! 1
  44.  
  45. rem display everything using VT100 2J sequence to clear the screen first.
  46. <nul set /p "=%ESC%[2J!screen0!"
  47. <nul set /p "=%ESC%[0;0H!screen1!%ESC%[0m"
  48.  
  49. rem update both screens
  50. set "screen0="
  51. set "screen1="
  52.  
  53. )
  54. rem end infinite loop ------ (but there is no end, it's infinite.) --------------------------
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. :macros
  74. set ^"LF=^
  75.  
  76. ^" Above empty line is required - do not remove
  77. set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
  78. for /F %%a in ('echo prompt $E^| cmd') do set "ESC=%%a"
  79. <nul set /p "=!esc![?25l"
  80.  
  81. cls
  82.  
  83. rem %plot% x y 0-255 0-255 CHAR
  84. set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-6" %%1 in ("^!args^!") do (%\n%
  85. set "screen%%6=^!screen%%6^!!esc![%%2;%%1H!esc![38;5;%%3m!esc![48;5;%%4m%%~5!esc![0m"%\n%
  86. )) else set args=
  87.  
  88. rem %fastCircle% x y ch cw color screenID
  89. set fastCircle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-8" %%1 in ("^!args^! sin^(x^) cos^(x^)") do (%\n%
  90. for /l %%a in (0,30,360) do (%\n%
  91. set /a "xa=%%~3 * ^!%%~7:x=%%a^! + %%~1"%\n%
  92. set /a "ya=%%~4 * ^!%%~8:x=%%a^! + %%~2"%\n%
  93. for /f "tokens=1,2" %%x in ("^!xa^! ^!ya^!") do ^!plot^! %%x %%y %%~5 0 Û %%6%\n%
  94. )%\n%
  95. )) else set args=
  96.  
  97. set /a "PI=(35500000/113+5)/10, PI_div_2=(35500000/113/2+5)/10, PIx2=2*PI, PI32=PI+PI_div_2"
  98. 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"
  99. 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"
  100. 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"
  101. set "_SIN="
  102. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement