' This program exported from BASIC Anywhere Machine (Version [5.2.3].[2023.12.16.16.28]) on 2024.02.24 at 00:27 (Coordinated Universal Time)
_TITLE "Mesmerizing Swirly Thing"
' This program is a port and mod by Charlie Veniot
' of a "QBasic" program by Cory Smith  (original code in comments below this program)

OPTION EXPLICIT

DIM sx% = 640 , sy% = 512
DIM sxh% = fix( sx% / 2 ), syh% = fix( sy% / 2 )
DIM s#( syh% )
DIM c#( syh% )

DIM r1# = INT( RND * 256 ), g1# = INT( RND * 256 ), b1# = INT( RND * 256 )
DIM r2% = 0 , g2% = 0 , b2% = 0 
DIM rinc# = 0 , ginc# = 0 , binc# = 0

DIM adj# = 0.0001, adjinc# = 0.25
DIM adj_bound% = 39
DIM r#, t#, u#, v#, i#, f#
DIM x%, y%

SCREEN _NEWIMAGE( sx%, sy%, 27 )
_DISPLAY

DO
  COLOR _RGB( r1#, g1#, b1# )
  FOR x% = 0 TO ( syh% - 1 )
    LET r# = x% / ( syh% - 1 )
    LET t# = adj# * r# * r# * SIN ( r# )
    LET s#( x% ) = SIN ( t# )
    LET c#( x% ) = COS ( t# )
  NEXT
  FOR y% = 0 TO YMAX STEP 1 : FOR x% = 0 TO XMAX STEP 1
    LET u# = ( x% / sxh% - 1 ) * 4 / 3
    LET v# = y% / syh% - 1
    LET i# = syh% - 1 - SQR ( u# * u# + v# * v# ) * ( syh% - 1 )
    LET i# = - i# * ( i# > 0 )
    LET f# = 20 * ( u# * c#( i# ) - v# * s#( i# ) )
    LET f# = f# - INT ( f# )
    IF f# > .5 THEN pset ( x% , y% )
  NEXT x% : NEXT y%
  _DISPLAY
  _DELAY 0.0001 * 1000 ^ ( adj# / adj_bound% )
  CLS
  IF adj# >  adj_bound% THEN adjinc# = -0.25 : _delay 1 : GOSUB NewColorTarget
  IF adj# < -adj_bound% THEN adjinc# =  0.25 : _delay 1 : GOSUB NewColorTarget
  r1# = r1# + rinc# : g1# = g1# + ginc# : b1# = b1# + binc#

  adj# = adj# + adjinc#
LOOP

NewColorTarget:

  r2% = INT( RND * 256 ) : g2% = INT( RND * 256 ) : b2% = INT( RND * 256 )
  rinc# = ( r2% - r1# ) / ( adj_bound% * 9 ) : ginc# = ( g2% - g1# ) / ( adj_bound% * 9 ) : binc# = ( b2% - b1# ) / ( adj_bound% * 9 )

RETURN

' 🟠🟠🟠🟠🟠🟠 Original code by Cory Smith 

'REM Vasarely - ish
'SCREEN 9 : WINDOW SCREEN ( 0 , -187 ) - ( 1279 , 1211 )
'VDU 5
'DIM S ( 512 )
'DIM C ( 512 )
'FOR x = 0 TO 511
'r = x / 511
't = 4 * r * r * SIN ( r )
'S ( x ) = SIN ( t )
'C ( x ) = COS ( t )
'NEXT
'FOR y = 0 TO 1023 STEP 4
'FOR x = 0 TO 1279 STEP 2
'u = ( x / 640 - 1 ) * 4 / 3
'v = y / 512 - 1
'i = 511 - SQR ( u * u + v * v ) * 511
'i = - i * ( i > 0 )
'f = 20 * ( u * C ( i ) - v * S ( i ) )
'f = f - INT ( f )
'IF f > .5 PSET ( x , y )
'NEXT
'NEXT
'DO
'LOOP UNTIL 0
'REM