Balls and colors moving around, what's not to like? :)
Hey is that Ken I see using a CircleFill SUB? Wow welcome to the new world! ;-))
I really don't know how the SIN and COS works, but it does. :)
You are changing the angle when you hit a border, dx and dy usually denote the change in x or y from one loop to the next. da for angle change would make this a little clearer.
Basically when you hit a border you change the sign of dx or dy depending if you hit the floor or ceiling change y component, hit walls = change x component -1*dx or -1*dy just changes the direction from up to down or vice versa of left to right in dx or vice versa.
da can be calculated from dx and dy or vice versa, eg
'find dx, dy from a (not da)
dx = speed *cos(a) ' a is ball angle (da is a change)
dy = speed *sin(a)
da = _atan2(dy, dx) ' I think
yeah this probably not going anywhere but if I keep plugging away... ;-))
a
= _PI / 4 ' this is 45 degrees in radians pi is 180, 2*pi full circle = 360
' 45 degrees is SE in QB64 about 4:30 o'clock
' dx should be positve, dy also positive
speed = 1
dx
= speed
* COS(a
) ' a is ball angle (da is a change)