Random Walk

This program produces a pattern by randomly drawing a coloured disk either abover, below, left or right of the previous disk.

     REM random walk
     REM T Street (superdecade Games)
     
MODE 10 : OFF
     
REM greyish background
     
COLOUR 1, 220, 220, 220
     COLOUR 129 : CLS
     
REM black outline
     
COLOUR 2, 0,0,0

     size% = 42
     REM start position
     
x% = 720
     y% = 576

     REM main loop
     
REPEAT
       
*refresh off
       REM get a new random colour
       
COLOUR 1, 0, RND(255), RND(255)
       REM draw black border
       
GCOL 0,2
       REM draw a circle
       
CIRCLE FILL  x%, y%, size% DIV 2
       REM draw coloured center
       
GCOL 0,1
       CIRCLE FILL  x%, y%, size% DIV 2 - 4
       *refresh on
       REM make a random walk
       
CASE RND(4) OF
         WHEN 
1 x% += size%
         WHEN 2 x% -= size%
         WHEN 3 y% += size%
         WHEN 4 y% -= size%
       ENDCASE

       
REM wait a mo'
       
WAIT 5

     UNTIL FALSE


A random walk.  Note, it is possible for the disks to 'walk' off the edge of the screen.
The following program prevents the disks from walking off the edge of the screen, by 'nudging' them back on if they cross the line.

     REM random walk 2
     REM T Street (superdecade Games)
     
MODE 10 : OFF
     
REM greyish background
     
COLOUR 1, 220, 220, 220
     COLOUR 129 : CLS
     
REM black outline
     
COLOUR 2, 0,0,0

     size% = 42
     REM start position
     
x% = 720
     y% = 576

     REM main loop
     
REPEAT
       
*refresh off
       REM get a new random colour
       
COLOUR 1, 0, RND(255), RND(255)
       REM draw black border
       
GCOL 0,2
       REM draw a circle
       
CIRCLE FILL  x%, y%, size% DIV 2
       REM draw coloured center
       
GCOL 0,1
       CIRCLE FILL  x%, y%, size% DIV 2 - 4
       *refresh on
       REM make a random walk
       
CASE RND(4) OF
         WHEN 
1 x% += size%
         WHEN 2 x% -= size%
         WHEN 3 y% += size%
         WHEN 4 y% -= size%
       ENDCASE

       
REM check disk hasn't walked off the screen
       
IF x%<0 THEN x% += (size%*2)
       IF x%>1440 THEN x% -= (size%*2)
       IF y%<0 THEN y% += (size%*2)
       IF y%>1152 THEN y% -= (size%*2)
       REM wait a mo'
       
WAIT 5

     UNTIL FALSE


Another random walk.  How would you change the size of the disks?  How would you change the size of the border?  How would you speed up the walk?
Another version of the program.  This time, the current disk momentarily blinks red as it is drawn.  Also, the process speed is increased and the size of disk has been increased.

     REM random walk 3
     
MODE 10 : OFF
     
REM greyish background
     
COLOUR 1, 220, 220, 220
     COLOUR 129 : CLS
     
REM black outline
     
COLOUR 2, 0,0,0
     REM red highlight
     
COLOUR 3, 255, 0, 0

     size% = 100
     REM start position
     
x% = 720
     y% = 576

     REM main loop
     
REPEAT
       
*refresh off
       REM get a new random colour
       
COLOUR 1, 0, RND(255), RND(255)
       REM draw black border
       
GCOL 0,2
       REM draw a circle
       
CIRCLE FILL  x%, y%, size% DIV 2
       REM draw coloured center
       
GCOL 0,3
       CIRCLE FILL  x%, y%, size% DIV 2 - 4
       *refresh on
       WAIT 2
       GCOL 0,1
       CIRCLE FILL  x%, y%, size% DIV 2 - 4

       REM make a random walk
       
CASE RND(4) OF
         WHEN 
1 x% += size%
         WHEN 2 x% -= size%
         WHEN 3 y% += size%
         WHEN 4 y% -= size%
       ENDCASE

       
REM check disk hasn't walked off the screen
       
IF x%<0 THEN x% += (size%*2)
       IF x%>1440 THEN x% -= (size%*2)
       IF y%<0 THEN y% += (size%*2)
       IF y%>1152 THEN y% -= (size%*2)
       REM wait a mo'
       
WAIT 1

     UNTIL FALSE


Red marks the current position of the 'walker'
In the following program, the random walk is determined not by a random number, but by the ASCII value of the string the user types in at the beginning, thus repeating patterns can be generated.

     REM random walk 4
     REM T Street (superdecade Games)
     
MODE 10 : OFF
     REPEAT
       INPUT 
"Enter a string ( more than 2 characters ) : " astring$
     UNTIL LEN(astring$) > 2

     REM greyish background
     
COLOUR 1, 220, 220, 220
     COLOUR 129 : CLS
     
REM black outline
     
COLOUR 2, 0,0,0

     size% = 36
     REM start position
     
x% = 720
     y% = 576

     n% = 1 : REM poition in string
     REM main loop
     
REPEAT
       
*refresh off
       REM get a new random colour
       
COLOUR 1, 0, RND(255), RND(255)
       REM draw black border
       
GCOL 0,2
       REM draw a circle
       
CIRCLE FILL  x%, y%, size% DIV 2
       REM draw coloured center
       
GCOL 0,1
       CIRCLE FILL  x%, y%, size% DIV 2 - 4
       *refresh on
       REM make a random walk
       
a% = ASC(MID$(astring$, n%, 1)) MOD 4 + 1
       n% += 1
       IF n% > LEN(astring$) n% = 1
       CASE a% OF
         WHEN 
1 x% += size%
         WHEN 2 x% -= size%
         WHEN 3 y% += size%
         WHEN 4 y% -= size%
       ENDCASE

       
REM wait a mo'
       
WAIT 5

     UNTIL FALSE