Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & setlocal enableDelayedExpansion
- :: create array of lines height(40) with a string length of width(50)
- set /a "width=50 - 1", "height=40 - 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! "
- for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
- mode con: cols=%conWidth% lines=%conHeight%
- :: create %balls% number of ball objects.
- set "balls=5"
- for /l %%b in (1,1,%balls%) do (
- rem r = radius
- set /a "r[%%b]=!random! %% 5 + 2"
- rem x position
- set /a "x[%%b]=!random! %% width + r[%%b]"
- rem y position
- set /a "y[%%b]=!random! %% height + r[%%b]"
- rem i = x direction
- set /a "i[%%b]=!random! %% 3 + 1"
- rem j = y direction
- set /a "j[%%b]=!random! %% 2 + 1"
- rem c = character
- set /a "c[%%b]=%%b"
- rem bounce limits
- set /a "bmaxW[%%b]=width - r[%%b]"
- set /a "bmaxH[%%b]=height - r[%%b]"
- set /a "bmin[%%b]=r[%%b]"
- )
- :: create %plot% and %circle% macro functions.--------------------------------------------------------
- set ^"LF=^
- ^" Above empty line is required - do not remove
- set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"
- set plot=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-3" %%1 in ("^!args^!") do (%\n%
- set /a "_y=%%2", "_x=%%1", "_x2=%%1 + 1"%\n%
- for /f "tokens=1-4" %%a in ("_y ^!_y^! ^!_x^! ^!_x2^!") do set "_[^!%%a^!]=^!_[%%b]:~0,%%c^!%%3^!_[%%b]:~%%d^!"%\n%
- )) else set args=
- :: %CIRCLE%
- set circle=for %%# in (1 2) do if %%#==2 ( for /f "tokens=1-5" %%1 in ("^!args^!") do (%\n%
- for /l %%y in (-%%3,1,%%3) do for /l %%x in (-%%3,1,%%3) do (%\n%
- set /a "S=(%%x * %%x) + (%%y * %%y) - (%%3 * %%3)", "_3div2=%%3 / 2"%\n%
- for /f "tokens=1,2" %%a in ("^!S^! ^!_3div2^!") do (%\n%
- if "%%5" equ "/f" ( if %%a leq 1 ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ) else if "%%5" equ "/n" ( if %%a geq -%%3 ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ) else if %%a geq -%%3 if %%a leq %%b ^!plot^! %%x+%%1 %%y+%%2 %%4 %\n%
- ))%\n%
- set "s="%\n%
- )) else set args=
- :: end of macros -------------------------------------------------------------------------------------
- rem infinite loop of bouncing balls
- for /l %%# in () do ( for /l %%b in (1,1,%balls%) do (
- set /a "x[%%b]+=i[%%b]"
- set /a "y[%%b]+=j[%%b]"
- if !x[%%b]! geq !bmaxW[%%b]! set /a "x[%%b]=bmaxW[%%b]", "i[%%b]*=-1"
- if !y[%%b]! geq !bmaxH[%%b]! set /a "y[%%b]=bmaxH[%%b]", "j[%%b]*=-1"
- if !x[%%b]! leq !bmin[%%b]! set /a "x[%%b]=bmin[%%b]", "i[%%b]*=-1"
- if !y[%%b]! leq !bmin[%%b]! set /a "y[%%b]=bmin[%%b]", "j[%%b]*=-1"
- %plot% !x[%%b]! !y[%%b]! !c[%%b]!
- %circle% !x[%%b]! !y[%%b]! !r[%%b]! .
- )
- cls
- echo= %outerBuffer%
- for /l %%a in (0,1,%height%) do echo= #!_[%%a]!#
- echo= %outerBuffer%
- for /l %%a in (0,1,%height%) do set "_[%%a]=%widthBuffer%"
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement