Ripples

Another simple program that works similarly to 'bubbles'. This time it represents 'ripples' on a pond.



      REM ripples
      REM Tim Goliath Street
    
      REM screen parameters
      X_WIDTH% = 1400
      Y_WIDTH% = 1200
    
      MODE 10  : OFF
    
      REM these are the parameters
      REM cool stuff happens when you change these
      REM ------------------------------------------
    
      MAX_SIZE% =6
      REM size of the ripple (5 - 10 )
    
      DELAY% = 4
      REM (1 very fast to 100 slow )
    
      RIPPLE_WIDTH% = 10
      REM spacing of the ripple (10-20)
    
      REM -----------------------------------------
    
    
    
      REM structure for storing data about each ripple
      MAX% = MAX_SIZE% * 2
      DIM ripple{( MAX% ) x%, y%, age% }
    
    
      REM pointers
      makeRipple% = 0 : REM pointer to the current ripple
    
      REM colours
      blue% = 4
      cyan% = 6
      black% = 0
    
      REM clear the screen to blue
      COLOUR blue% + 128 : CLS
    
      REM ==========================
      REM MAIN LOOP
      REM ==========================
      REPEAT
        REM start a new ripple at a random location
        REM a ripple has an x and a y coord
        REM and an age
        REM a bubble with an age of zero is not displayed
        REM a bubble with an age less than the MAX_SIZE% will have that many cyan ripples
        REM a bubble with an age greater than the MAX SIZE% will have the largest of
        REM age - MAX_SIZE% ripples left!
        x% = RND(X_WIDTH%)
        y% = RND(Y_WIDTH%)
        age% = 1
      
        REM store new ripple
        ripple{(makeRipple%)}.x% = x%
        ripple{(makeRipple%)}.y% = y%
        ripple{(makeRipple%)}.age% = age%
      
        REM increment the ripple pointer
        makeRipple% += 1
      
        REM check boundary
        IF makeRipple% > MAX% THEN
          makeRipple% = 0
        ENDIF
      
        REM for each ripple, display the current number of outer rings
        FOR n% = 1 TO MAX%
        
          REM find the age of this ripple
          CASE TRUE OF
            
            WHEN ripple{(n%)}.age%>0 AND ripple{(n%)}.age%<MAX_SIZE%
              REM this is a young ripple, getting bigger each loop
              REM display a number of concentric circles equal to its age
              GCOL cyan%
              FOR m% = 1 TO ripple{(n%)}.age%
                CIRCLE ripple{(n%)}.x%, ripple{(n%)}.y%, RIPPLE_WIDTH%*m%
              NEXT
              REM make this ripple one point older
              ripple{(n%)}.age% +=1
            
            WHEN ripple{(n%)}.age%>=MAX_SIZE%
              REM this is an old ripple
              REM display the full amount of concentric circles
              GCOL cyan%
              FOR m% = 1 TO MAX_SIZE%
                CIRCLE ripple{(n%)}.x%, ripple{(n%)}.y%, RIPPLE_WIDTH%*m%
              NEXT
              REM now over-write some of the inner circles with the background colour
              GCOL blue%
              FOR m% = 1 TO ripple{(n%)}.age%-MAX_SIZE%
                CIRCLE ripple{(n%)}.x%, ripple{(n%)}.y%, RIPPLE_WIDTH%*m%
              NEXT
              REM make this ripple one point older
              ripple{(n%)}.age% +=1
              REM eventually this ripple 'expires'
              IF ripple{(n%)}.age% >2*MAX_SIZE% THEN
                ripple{(n%)}.age% = 0
              ENDIF
          ENDCASE
          REM go and look at the next ripple
        NEXT n%
      
        WAIT DELAY% : REM wait a mo
      
      UNTIL FALSE