Code: Select all
DIM v(2,1),p(1):v()=320,500,640:REPEAT p()=p()/2+v(RND(3)-1,0TO):PLOT p(0),p(1):UNTIL 0
Code: Select all
DIM v(2,1),p(1):v()=320,500,640:REPEAT p()=p()/2+v(RND(3)-1,0TO):PLOT p(0),p(1):UNTIL 0
Here's a breakdown of how it works:Richard Russell wrote: ↑Wed 20 Aug 2025, 15:33Code: Select all
DIM v(2,1),p(1):v()=320,500,640:REPEAT p()=p()/2+v(RND(3)-1,0TO):PLOT p(0),p(1):UNTIL 0
Code: Select all
DIM v(2,1),p(1) : REM v() holds the coordinates of the three vertices, p() the current point
v()=320,500,640 : REM Initialise v() to the three vertices: (320,500), (640,0) and (0,0)
REPEAT : REM Start the loop
p()=p()/2+v(RND(3)-1,0TO) : REM Move the current point half way to a randomly-chosen vertex
PLOT p(0),p(1) : REM Plot the current point
UNTIL 0 : REM Loop for ever
Code: Select all
Time spent profiling: 11.528 seconds.
0: DIM v(2,1),p(1):v()=320,500,640
0: REPEAT
2788: 24.18 p()=p()/2+v(RND(3)-1,0TO)
8624: 74.81 PLOT p(0),p(1)
116: 1.01 UNTIL 0
0: Libraries and immediate mode
Code: Select all
0: DIM v(2,1),p(1):v()=320,500,640
0: REPEAT
198: 1.98 p()=p()/2+v(RND(3)-1,0TO)
9776: 97.76 PLOT p(0),p(1)
26: 0.26 UNTIL 0