Advertisement
IcarusLives

animation

Nov 22nd, 2020
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.39 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3. call :macros
  4.  
  5. set /a "hei=60","wid=100"
  6. mode %wid%,%hei%
  7.  
  8. set /a "points=4", "deg=360 / points"
  9. for /l %%a in (1,1,!points!) do set /a "i%%a=!random! %% 3 + 1", "j%%a=!random! %% 2 + 1"
  10.  
  11.  
  12. :ENGINE
  13.     for /l %%# in () do (
  14.    
  15.         set /a "frames+=1"
  16.        
  17.         if !frames! lss 100 (
  18.    
  19.             rem give points their direction in DEGREES
  20.             set /a "angle[1]+=3" & for /l %%a in (2,1,!points!) do (
  21.                 set /a "lastPoint=%%a - 1"
  22.                 set /a "angle[%%a]=angle[!lastPoint!] + deg"
  23.             )
  24.            
  25.             rem apply DEGREES to sin/cos + y;x position
  26.             for /l %%a in (1,1,!points!) do (
  27.                 set /a "spx%%a=10 * !cos:x=angle[%%a]! + wid / 2"
  28.                 set /a "spy%%a=10 * !sin:x=angle[%%a]! + hei / 2"
  29.             )
  30.            
  31.             rem draw the lines
  32.             set /a "halfPoints=points / 2"
  33.             for /l %%a in (1,1,!halfPoints!) do (
  34.                 set /a "skip=%%a + 2"
  35.                 %line% spx%%a spy%%a spx!skip! spy!skip! %%a
  36.                 set "screen=!screen!!$line!"
  37.             )
  38.        
  39.         ) else (
  40.            
  41.             rem bouncing ball animation after 100 frames
  42.             for /l %%a in (1,1,!points!) do (
  43.                 rem move ball according to trajectory j;i
  44.                 set /a "spx%%a+=i%%a",  "spy%%a+=j%%a"
  45.                 rem bounce if collide with borders
  46.                 if !spx%%a! geq %wid% set /a "spx%%a=wid", "i%%a*=-1"
  47.                 if !spy%%a! geq %hei% set /a "spy%%a=hei", "j%%a*=-1"
  48.                 if !spx%%a! leq 0  set /a "spx%%a=3", "i%%a*=-1"
  49.                 if !spy%%a! leq 0  set /a "spy%%a=3", "j%%a*=-1"
  50.                
  51.                 rem draw to screen
  52.                 set "screen=!screen!%esc%[38;5;%%am%esc%[!spy%%a!;!spx%%a!HÛ"
  53.             )
  54.             rem artificial delay
  55.             for /l %%. in (1,20,1000000) do rem
  56.         )
  57.  
  58.         rem display
  59.         <nul set /p "=%esc%[2J!screen!" & set "screen="
  60.     )
  61. exit
  62.  
  63. :macros
  64. (set \n=^^^
  65. %= This creates an escaped Line Feed - DO NOT ALTER =%
  66. )
  67. ( for /f %%a in ('echo prompt $E^| cmd') do set "esc=%%a" ) & <nul set /p "=!esc![Û25l"
  68.  
  69. REM Û
  70. 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"
  71. set "sin=(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"
  72. set "cos=(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"
  73.  
  74. rem line x0 y0 x1 y1 color
  75. set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
  76.     if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
  77.     set "$line=%esc%[38;5;^!hue^!m"%\n%
  78.     set /a "xa=%%~1", "ya=%%~2", "xb=%%~3", "yb=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
  79.     if ^^!dy^^! lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set "stepy=1" )%\n%
  80.     if ^^!dx^^! lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set "stepx=1" )%\n%
  81.     set /a "dx<<=1", "dy<<=1"%\n%
  82.     if ^^!dx^^! gtr ^^!dy^^! (%\n%
  83.         set /a "fraction=dy - (dx >> 1)"%\n%
  84.         for /l %%x in (^^!xa^^!,^^!stepx^^!,^^!xb^^!) do (%\n%
  85.             if ^^!fraction^^! geq 0 set /a "ya+=stepy", "fraction-=dx"%\n%
  86.             set /a "fraction+=dy"%\n%
  87.             set "$line=^!$line^!%esc%[^!ya^!;%%xHÛ"%\n%
  88.         )%\n%
  89.     ) else (%\n%
  90.         set /a "fraction=dx - (dy >> 1)"%\n%
  91.         for /l %%y in (^^!ya^^!,^^!stepy^^!,^^!yb^^!) do (%\n%
  92.             if ^^!fraction^^! geq 0 set /a "xa+=stepx", "fraction-=dy"%\n%
  93.             set /a "fraction+=dx"%\n%
  94.             set "$line=^!$line^!%esc%[%%y;^!xa^!HÛ"%\n%
  95.         )%\n%
  96.     )%\n%
  97.     set "_$_=^!_$_^!^!$line^!"%\n%
  98. )) else set args=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement