Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- call :canvas 50 40
- set "balls=6"
- for /l %%b in (1,1,%balls%) do ( call :generate_balls %%b )
- for /l %%# in () do ( for /l %%b in (1,1,%balls%) do (
- call :moveObjects %%b
- call :edges %%b
- call :plot !x[%%b]! !y[%%b]! !c[%%b]!
- call :circle !x[%%b]! !y[%%b]! !r[%%b]! .
- )
- call :showCanvas
- call :updateCanvas
- )
- :moveObjects
- set /a "x[%1]+=i[%1]"
- set /a "y[%1]+=j[%1]"
- goto :eof
- :edges
- if !x[%1]! geq !bmaxW[%1]! set /a "x[%1]=bmaxW[%1]", "i[%1]*=-1"
- if !y[%1]! geq !bmaxH[%1]! set /a "y[%1]=bmaxH[%1]", "j[%1]*=-1"
- if !x[%1]! leq !bmin[%1]! set /a "x[%1]=bmin[%1]", "i[%1]*=-1"
- if !y[%1]! leq !bmin[%1]! set /a "y[%1]=bmin[%1]", "j[%1]*=-1"
- goto :eof
- :generate_balls
- set /a "r[%1]=3"
- set /a "x[%1]=!random! %% width + r[%1]"
- set /a "y[%1]=!random! %% height + r[%1]"
- set /a "i[%1]=!random! %% 3 + 1"
- set /a "j[%1]=!random! %% 2 + 1"
- set /a "c[%1]=%1"
- set /a "bmaxW[%1]=width - r[%1]"
- set /a "bmaxH[%1]=height - r[%1]"
- set /a "bmin[%1]=r[%1]"
- goto :eof
- :canvas
- set /a "width=%~1 - 1", "height=%~2 - 1", "conWidth=width + 5", "conHeight=height + 6", "_=0"
- for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
- for /l %%a in (0,1,%width%) do set "widthBuffer=!widthBuffer! "
- call :updateCanvas
- call :cursorpos
- if exist "%temp%\cursorpos.exe" ( set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
- mode con: cols=%conWidth% lines=%conHeight%
- goto :eof
- :updateCanvas
- for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
- goto :eof
- :showCanvas
- %cls%
- echo= %outerBuffer%
- for /l %%a in (0,1,%height%) do echo= #!_[%%a]!#
- echo= %outerBuffer%
- if "%~1" equ "/u" for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
- goto :eof
- goto :eof
- :plot x y
- setlocal
- set "c=%~3"
- set /a "_y=%~2", "_x=%~1", "_x2=%~1 + 1"
- (endlocal
- set "_[%_y%]=!_[%_y%]:~0,%_x%!%c:~0,1%!_[%_y%]:~%_x2%!"
- )
- goto :eof
- :circle x y r
- set /a "___rr=%~3"
- for /l %%y in (-%___rr%,1,%___rr%) do for /l %%x in (-%___rr%,1,%___rr%) do (
- set /a "t=-___rr - 1", "S=(%%x * %%x) + (%%y * %%y) - (___rr * ___rr) - t - 1"
- if !S! geq !t! if !S! leq 1 (
- set /a "_x=%%x + %~1", "_y=%%y + %~2"
- set /a "_x2=_x + 1"
- call set "_[!_y!]=%%_[!_y!]:~0,!_x!%%%~4%%_[!_y!]:~!_x2!%%"
- )
- )
- for %%a in (t S _x _y _x2 ___rr) do set "%%a="
- goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement