Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- call :macros
- set /a "hei=60","wid=100"
- mode %wid%,%hei%
- set /a "points=4", "deg=360 / points"
- for /l %%a in (1,1,!points!) do set /a "i%%a=!random! %% 3 + 1", "j%%a=!random! %% 2 + 1"
- :ENGINE
- for /l %%# in () do (
- set /a "frames+=1"
- if !frames! lss 100 (
- rem give points their direction in DEGREES
- set /a "angle[1]+=3" & for /l %%a in (2,1,!points!) do (
- set /a "lastPoint=%%a - 1"
- set /a "angle[%%a]=angle[!lastPoint!] + deg"
- )
- rem apply DEGREES to sin/cos + y;x position
- for /l %%a in (1,1,!points!) do (
- set /a "spx%%a=10 * !cos:x=angle[%%a]! + wid / 2"
- set /a "spy%%a=10 * !sin:x=angle[%%a]! + hei / 2"
- )
- rem draw the lines
- set /a "halfPoints=points / 2"
- for /l %%a in (1,1,!halfPoints!) do (
- set /a "skip=%%a + 2"
- %line% spx%%a spy%%a spx!skip! spy!skip! %%a
- set "screen=!screen!!$line!"
- )
- ) else (
- rem bouncing ball animation after 100 frames
- for /l %%a in (1,1,!points!) do (
- rem move ball according to trajectory j;i
- set /a "spx%%a+=i%%a", "spy%%a+=j%%a"
- rem bounce if collide with borders
- if !spx%%a! geq %wid% set /a "spx%%a=wid", "i%%a*=-1"
- if !spy%%a! geq %hei% set /a "spy%%a=hei", "j%%a*=-1"
- if !spx%%a! leq 0 set /a "spx%%a=3", "i%%a*=-1"
- if !spy%%a! leq 0 set /a "spy%%a=3", "j%%a*=-1"
- rem draw to screen
- set "screen=!screen!%esc%[38;5;%%am%esc%[!spy%%a!;!spx%%a!HÛ"
- )
- rem artificial delay
- for /l %%. in (1,20,1000000) do rem
- )
- rem display
- <nul set /p "=%esc%[2J!screen!" & set "screen="
- )
- exit
- :macros
- (set \n=^^^
- %= This creates an escaped Line Feed - DO NOT ALTER =%
- )
- ( for /f %%a in ('echo prompt $E^| cmd') do set "esc=%%a" ) & <nul set /p "=!esc![Û25l"
- REM Û
- 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=(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=(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"
- rem line x0 y0 x1 y1 color
- set line=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- if "%%~5" equ "" ( set "hue=30" ) else ( set "hue=%%~5")%\n%
- set "$line=%esc%[38;5;^!hue^!m"%\n%
- set /a "xa=%%~1", "ya=%%~2", "xb=%%~3", "yb=%%~4", "dx=%%~3 - %%~1", "dy=%%~4 - %%~2"%\n%
- if ^^!dy^^! lss 0 ( set /a "dy=-dy", "stepy=-1" ) else ( set "stepy=1" )%\n%
- if ^^!dx^^! lss 0 ( set /a "dx=-dx", "stepx=-1" ) else ( set "stepx=1" )%\n%
- set /a "dx<<=1", "dy<<=1"%\n%
- if ^^!dx^^! gtr ^^!dy^^! (%\n%
- set /a "fraction=dy - (dx >> 1)"%\n%
- for /l %%x in (^^!xa^^!,^^!stepx^^!,^^!xb^^!) do (%\n%
- if ^^!fraction^^! geq 0 set /a "ya+=stepy", "fraction-=dx"%\n%
- set /a "fraction+=dy"%\n%
- set "$line=^!$line^!%esc%[^!ya^!;%%xHÛ"%\n%
- )%\n%
- ) else (%\n%
- set /a "fraction=dx - (dy >> 1)"%\n%
- for /l %%y in (^^!ya^^!,^^!stepy^^!,^^!yb^^!) do (%\n%
- if ^^!fraction^^! geq 0 set /a "xa+=stepx", "fraction-=dy"%\n%
- set /a "fraction+=dx"%\n%
- set "$line=^!$line^!%esc%[%%y;^!xa^!HÛ"%\n%
- )%\n%
- )%\n%
- set "_$_=^!_$_^!^!$line^!"%\n%
- )) else set args=
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement