_TITLE "Delta angle by bplus 2018-10-05"
' collisions on the topological rim of circle
'given 2 ball angles A and B there are 2 distances the Major and the Minor
' make a function that returns the Minor, so don't have to calculate the x, y coordinates of each ball
'QB64 X 64 version 1.2 20180228/86 from git b301f92
CONST PI
= 3.141492653589793 CONST PI2
= 1.570796326794897 a
AS SINGLE ' all balls are located by angle a da
AS SINGLE ' all balls move according to delta angle
nBalls = 7
DIM s
(1 TO nBalls
) AS ballType
'system array nDiv = 24 'divide circle n times
angle = 2 * PI / nDiv ' 20 degrees, EDIT: no now it's 15 degrees! 360 / 24 = 15
smallr
= BIGR
* SIN(.5 * angle
)
'initialize system, setup like Fellippe's only make it a 2D system
s(i).a = PI / 2 - (nBalls * PI / 20) - (nBalls) * .5 * angle + i * angle + i * PI / 20 'the last + to separate balls
IF i
= nBalls
THEN s
(i
).da
= PI
/ 30 ELSE s
(i
).da
= 0 s
(i
).c
= _RGBA32((nBalls
- i
+ 2) * 20, (nBalls
- i
+ 2) * 20, (nBalls
- i
+ 2) * 20, 100) 'use transpaency to check overlapl = 30
'collision check just check the ball after ball i
IF MinorDistance!
(s
(i
).a
, s
(j
).a
) < angle
THEN 'collision
'update
s(i).a = s(i).a + s(i).da
fcirc x0
+ BIGR
* COS(s
(i
).a
), y0
+ BIGR
* SIN(s
(i
).a
), smallr
, s
(i
).c
l = l + .1
' all angles are in radian units
FUNCTION MinorDistance!
(angleA
, angleB
) ab = angleA - angleB
IF ab
< 0 THEN ab
= ab
+ 2 * PI
ba = angleB - angleA
IF ba
< 0 THEN ba
= ba
+ 2 * PI
IF ab
< ba
THEN MinorDistance!
= ab
ELSE MinorDistance!
= ba
'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
), K
, BF
RadiusError = RadiusError + Y * 2 + 1
LINE (CX
- Y
, CY
- X
)-(CX
+ Y
, CY
- X
), K
, BF
LINE (CX
- Y
, CY
+ X
)-(CX
+ Y
, CY
+ X
), K
, BF
X = X - 1
RadiusError = RadiusError - X * 2
Y = Y + 1
LINE (CX
- X
, CY
- Y
)-(CX
+ X
, CY
- Y
), K
, BF
LINE (CX
- X
, CY
+ Y
)-(CX
+ X
, CY
+ Y
), K
, BF