' Based on https://qb64phoenix.com/qb64wiki/index.php/DISPLAY
' BASIC Anywhere Machine mod by Charlie Veniot
STRUCTURE structBall
  x as integer
  y as integer
  clr as integer
  px as integer
  py as integer
  dx as integer
  dy as integer
END STRUCTURE
LET MaxBallCount% = 400
DIM as structBall Ball(1 to MaxBallCount%)
DIM dir%(0 to 1)
dir%(0) = 1 : dir%(1) = -1 
FOR i = 1 TO MaxBallCount%
    Ball(i).x = int(rnd*640)
    Ball(i).y = int(rnd*480)
    Ball(i).clr = int(rnd*15) + 1
    Ball(i).dx = dir%(int(rnd*2))  *  (int(rnd*5)+1)
    Ball(i).dy = dir%(int(rnd*2))  *  (int(rnd*5)+1)
NEXT i
SCREEN 12
DO
    FOR i = 1 TO MaxBallCount%
        Ball(i).x = Ball(i).x + Ball(i).dx: Ball(i).y = Ball(i).y + Ball(i).dy
        IF Ball(i).x < 0 OR Ball(i).x > 639 THEN Ball(i).dx = -Ball(i).dx  'limit columns and reverse column direction each side
        IF Ball(i).y < 0 OR Ball(i).y > 479 THEN Ball(i).dy = -Ball(i).dy  'limit rows and reverse row direction top or bottom
        IF Ball(i).px <> Ball(i).x OR Ball(i).py <> Ball(i).y THEN FOR d = 3 to 3: CIRCLE (Ball(i).px, Ball(i).py), d, 0: NEXT 'erase
        FOR c = 3 TO 3: CIRCLE (Ball(i).x, Ball(i).y), c, Ball(i).clr: NEXT  'draw new circle at new position
        Ball(i).px = Ball(i).x: Ball(i).py = Ball(i).y        'save older coordinates to erase older circle next loop
    NEXT i
    _DISPLAY                'after new circle is set, show it
LOOP
END