Advertisement
IcarusLives

In-line - Bouncing balls

Mar 24th, 2017
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.40 KB | None | 0 0
  1. @echo off & setlocal enableDelayedExpansion
  2.  
  3.     set /a "width=50 - 1", "height=40 - 1", "conWidth=width + 5", "conHeight=height + 6", "_=0"
  4.     for /l %%a in (-2,1,%width%) do set "outerBuffer=!outerBuffer!#"
  5.     for /l %%a in (0,1,%width%)  do set "widthBuffer=!widthBuffer! "
  6.     for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
  7.     if exist "%temp%\cursorpos.exe" ( set "cls="%temp%\cursorpos.exe" 0 1" ) else ( set "cls=cls" )
  8.     mode con: cols=%conWidth% lines=%conHeight%
  9.  
  10.     set "balls=6"
  11.  
  12.     for /l %%b in (1,1,%balls%) do (
  13.         set /a "r[%%b]=3"
  14.         set /a "x[%%b]=!random! %% width + r[%%b]"
  15.         set /a "y[%%b]=!random! %% height + r[%%b]"
  16.         set /a "i[%%b]=!random! %% 3 + 1"
  17.         set /a "j[%%b]=!random! %% 2 + 1"
  18.         set /a "c[%%b]=%%b"
  19.         set /a "bmaxW[%%b]=width - r[%%b]"
  20.         set /a "bmaxH[%%b]=height - r[%%b]"
  21.         set /a "bmin[%%b]=r[%%b]"
  22.     )
  23.  
  24. rem inf_loop
  25. for /l %%# in () do ( for /l %%b in (1,1,%balls%) do (
  26.         set /a "x[%%b]+=i[%%b]"
  27.         set /a "y[%%b]+=j[%%b]"
  28.        
  29.         if !x[%%b]! geq !bmaxW[%%b]! set /a "x[%%b]=bmaxW[%%b]", "i[%%b]*=-1"
  30.         if !y[%%b]! geq !bmaxH[%%b]! set /a "y[%%b]=bmaxH[%%b]", "j[%%b]*=-1"
  31.         if !x[%%b]! leq !bmin[%%b]!  set /a "x[%%b]=bmin[%%b]",  "i[%%b]*=-1"
  32.         if !y[%%b]! leq !bmin[%%b]!  set /a "y[%%b]=bmin[%%b]",  "j[%%b]*=-1"
  33.        
  34.         call :plot !x[%%b]! !y[%%b]! !c[%%b]!
  35.         call :circle !x[%%b]! !y[%%b]! !r[%%b]! .
  36.     )
  37.     %cls%
  38.         echo= %outerBuffer%
  39.         for /l %%a in (0,1,%height%) do echo= #!_[%%a]!#
  40.         echo= %outerBuffer%
  41.     for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
  42. )
  43.  
  44. :plot x y
  45.     setlocal
  46.         set "c=%~3"
  47.         set /a "_y=%~2", "_x=%~1", "_x2=%~1 + 1"
  48.         (endlocal
  49.             set "_[%_y%]=!_[%_y%]:~0,%_x%!%c:~0,1%!_[%_y%]:~%_x2%!"
  50.         )
  51. goto :eof
  52.  
  53. :circle x y r
  54.     set /a "___rr=%~3"
  55.         for /l %%y in (-%___rr%,1,%___rr%) do for /l %%x in (-%___rr%,1,%___rr%) do (
  56.            
  57.             set /a "t=-___rr - 1", "S=(%%x * %%x) + (%%y * %%y) - (___rr * ___rr) - t - 1"
  58.             if !S! geq !t! if !S! leq 1 (  
  59.                 set /a "_x=%%x + %~1", "_y=%%y + %~2"
  60.                 set /a "_x2=_x + 1"
  61.                 call set "_[!_y!]=%%_[!_y!]:~0,!_x!%%%~4%%_[!_y!]:~!_x2!%%"
  62.             )  
  63.         )
  64.         for %%a in (t S _x _y _x2 ___rr) do set "%%a="
  65. goto :eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement