Random Walk 2

Continuing our Random Walk program, here is an example that uses coloured lines for the walk.  A new line is drawn to a random position of maximum radius no more than the square root of (2*size% squared).  The thickness of the line is controlled by the thickness% variable.

     REM random walker
     REM T Street
     
MODE 10 : OFF

     
x% = 720
     y% = 576

     size% = 300
     thickness% = 20

     col% = 0

     MOVE x%, y%

     REPEAT
       
REM find new coordinate
       REM within the bounds of the screen
       
REPEAT
         
plusx% = RND(size%) - size% DIV 2
         plusy% = RND(size%) - size% DIV 2
       UNTIL (x%+plusx%)>=0 AND (x%+plusx%)<1440 AND (y%+plusy%)>=0 AND (y%+plusy%)<1152

       REM get a new colour
       
COLOUR 1, 0, col%, 200
       col% += 1
       GCOL 0,1 : REM draw in this colour

       REM draw a new line
       
*refresh off
       FOR i% = 1 TO thickness%
         MOVE x%+i%, y%
         DRAW x%+plusx%+i%, y%+plusy%
       NEXT
       
* refresh on

       REM move to the end of the line
       REM ready for the next line
       
x% += plusx%
       y% += plusy%
       MOVE x%, y%

       REM wait a 'mo
       
WAIT 5

       REM should clear screen?
       
IF col%>255 THEN
         
col% = 0
         WAIT 50
         CLS
       ENDIF

     UNTIL FALSE




The following code produces THREE walkers.  Each start at random positions and have different thicknesses, colours and random lengths.

     REM three random walkers
     
MODE 10 : OFF

     
REM set up the walkers
     
DIM walker{(2) x%, y%, red%, green%, blue%, size%, thickness%, age% }

     screenwidth% = 1440 :
     screenheight% = 1152
     maxSize% = 400
     maxWidth% = 40

     REM initial positions
     
FOR i% =0 TO 2
       PROC_setInitialPosition( walker{(i%)} )
     NEXT

     
walker{(0)}.green% = 1 : walker{(0)}.blue% = 1
     walker{(1)}.green% = 1
     walker{(2)}.blue% = 1

     REPEAT
       
REM draw each walker
       
FOR i% = 0 TO 2
         PROC_drawNew( walker{(i%)} )
       NEXT
       
REM wait a 'mo
       
WAIT 5
     UNTIL FALSE


     
DEFPROC_setInitialPosition( this{} )
     REM random starting state for a walker
     
this.x% = RND(screenwidth%)
     this.y% = RND(screenheight%)
     this.size% = RND(maxSize%) +20
     this.thickness% = RND(maxWidth%) + 4
     this.age% = RND(255)
     ENDPROC


     
DEFPROC_drawNew( this{} )
     LOCAL plusx%, plusy%, x%, y%, i%
     x% = this.x%
     y% = this.y%
     REM get new position
     
REPEAT
       
plusx% = RND(this.size%) - this.size% DIV 2
       plusy% = RND(this.size%) - this.size% DIV 2
     UNTIL (x%+plusx%)>=0 AND (x%+plusx%)<screenwidth% AND (y%+plusy%)>=0 AND (y%+plusy%)<screenheight%

     COLOUR 1, this.red%*(255-this.age%), this.green%*(255-this.age%), this.blue%*(255-this.age%)
     GCOL 0,1

     REM draw line
     REM draw a new line
     
*refresh off
     FOR i% = 1 TO this.thickness%
       MOVE x%+i%, y%
       DRAW x%+plusx%+i%, y%+plusy%
     NEXT
     
* refresh on
     REM move to the end of the line
     REM ready for the next line
     
x% += plusx%
     y% += plusy%
     MOVE x%, y%

     this.x% = x%
     this.y% = y%

     this.age% += 1
     IF this.age% > 255 this.age% = 0
     ENDPROC


Random walker program with 3 walkers.


Three walker program shortly after the initial state.