I doubt Einstein will approve of my version of Brownian Motion but I am reading Walter Isaacson's book, Einstein: His Life and Universe, and want to get into experimental mode of thinking. I am also playing Mozart music. (He should approve of my attempts at least (and the music of course).)
_TITLE "Collision Study #3 Brownian Motion 2018-03-31 by bplus, press spacebar to toggle tracer" ' attempt to fix
clrMode = 1
balls = 500
DIM x
(balls
), y
(balls
), r
(balls
), c
(balls
), dx
(balls
), dy
(balls
), a
(balls
), rr
(balls
), gg
(balls
), bb
(balls
) r(i) = rand(15, 20)
x(i) = rand(r(i), xmax - r(i))
y(i) = rand(r(i), ymax - r(i))
c(i) = rand(1, 15)
dx(i) = rand(1, 5) * rdir
dy(i) = rand(1, 5) * rdir
rr(i) = rand(200, 255)
gg(i) = rand(200, 255)
bb(i) = rand(200, 255)
rr(i) = 0
gg(i) = 0
bb(i) = 0
'ready for collision
power1 = (dx(i) ^ 2 + dy(i) ^ 2) ^ .5
imoved = 0
IF SQR((x
(i
) - x
(j
)) ^ 2 + (y
(i
) - y
(j
)) ^ 2) < r
(i
) + r
(j
) THEN imoved = 1
a
(i
) = _ATAN2(y
(i
) - y
(j
), x
(i
) - x
(j
)) a
(j
) = _ATAN2(y
(j
) - y
(i
), x
(j
) - x
(i
)) 'update new dx, dy for i and j balls
power2 = (dx(j) ^ 2 + dy(j) ^ 2) ^ .5
power = (power1 + power2) / 2
dx
(i
) = power
* COS(a
(i
)) dy
(i
) = power
* SIN(a
(i
)) dx
(j
) = power
* COS(a
(j
)) dy
(j
) = power
* SIN(a
(j
)) x(i) = x(i) + dx(i)
y(i) = y(i) + dy(i)
x(j) = x(j) + dx(j)
y(j) = y(j) + dy(j)
x(i) = x(i) + dx(i)
y(i) = y(i) + dy(i)
IF x
(i
) < r
(i
) THEN dx
(i
) = -dx
(i
): x
(i
) = r
(i
) IF x
(i
) > xmax
- r
(i
) THEN dx
(i
) = -dx
(i
): x
(i
) = xmax
- r
(i
) IF y
(i
) < r
(i
) THEN dy
(i
) = -dy
(i
): y
(i
) = r
(i
) IF y
(i
) > ymax
- r
(i
) THEN dy
(i
) = -dy
(i
): y
(i
) = ymax
- r
(i
) COLOR _RGB32(rr
(i
) - 10 * rad
, gg
(i
) - 10 * rad
, bb
(i
) - 10 * rad
) fcirc x(i), y(i), rad
rand
= (RND * (hi
- lo
+ 1)) \
1 + lo
'Steve McNeil's copied from his forum note: Radius is too common a name
RadiusError = -subRadius
X = subRadius
Y = 0
' Draw the middle span here so we don't draw it twice in the main loop,
' which would be a problem with blending turned on.
LINE (CX
- X
, CY
)-(CX
+ X
, CY
), , BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), , BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), , BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), , BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), , BF
The motion along the edges has to be ignored of course, had to keep 2D molecules bounded in 2D container.