' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2024.09.09.00.00]) on 2025.06.17 at 02:00 (Coordinated Universal Time)
' Port and mod by Charlie Veniot
' of a Turbo Basic program shared by Shahid Altaf Qureshi
' with the BASIC Programming Language group on Facebook (https://www.facebook.com/share/p/164pEvqVpT/)

alert( "This program generates a new swirl every 4 seconds.\n" + _
       "To pause the program, click/touch the screen, and hold the click/touch.\n" + _
       "To resume the program, release the click/touch of the screen.")

SCREEN _NEWIMAGE( 643, 643, 17 )
DIM ca( 1 TO 60 )
xc = 320 : yc = xc

draw_cycle:
  GOSUB 🎨init_color_array
  r = 0
  theta = 0
  c = 1
  cr = INT( RND * 4 ) + 2
  DO WHILE r < 459
    x = INT( xc + r * COS( theta ) )
    y = INT( yc + r * SIN( theta ) )
    CIRCLE( x, y ), cr, 1, , , , T
    PAINT( x, y ), ca(c), 1
    CIRCLE( x, y ), cr, ca(c), , , , T
    IF INT(r) MOD 9 = 0 THEN SLEEP 0.001   ' 📑 force screen refresh every 9th loop iteration
    c = c + 1
    IF c > maxc THEN c = 1
    theta = theta + 0.07
    r = r + 0.1
  LOOP
  SLEEP 4
  IF _MOUSEBUTTON THEN WHILE _MOUSEBUTTON : WEND
  CLS
GOTO draw_cycle

END

🎨init_color_array:
  maxc = INT( RND * 59 ) + 2
  FOR i = 1 TO maxc
    ca(i) = INT( RND * 62 ) + 2 
  NEXT i
RETURN