'\begin{verbatim} 'This program simulates random walk paths (with uniform incerments) 'reflected at the boundaries of a region ' 'declarations of subs DECLARE SUB CenterPrint (Text$) ' minimal error handling - graphics card is required ON ERROR GOTO ErrTrap CLS 'request good graphics (some cards support SCREEN 7, etc) SCREEN 9 LOCATE 1, 1 'title CenterPrint "Path of reflected random walk" LOCATE 9, 1 'timer location PRINT "Timer" scale = 10 ' WINDOW (0, 0)-(scale, scale): VIEW (150, 100)-(600, 300) LINE (0, 0)-(scale, scale), 10, B': LINE (scale, scale)-(2 * scale, 0), 11, B FOR j = -4 TO 4 LINE (0, scale / 2 + j)-(scale / 50, scale / 2 + j), 2 NEXT j X = scale / 2 Y = scale / 2 dead = 0 T = 0 col = 14 * RND(1) speed = scale / 100 WHILE INKEY$ = "" 'infinite loop until a key is pressed T = T + 1 X0 = X Y0 = Y X = X + (RND(1) - 1 / 2) * speed Y = Y + (RND(1) - 1 / 2) * speed IF X < 0 THEN X = -X: col = 14 * RND(1) IF Y < 0 THEN Y = -Y: col = 14 * RND(1) IF X > scale THEN X = 2 * scale - X: col = 14 * RND(1) IF Y > scale THEN Y = 2 * scale - Y: col = 14 * RND(1) IF X > 2 * scale THEN X = 4 * scale - X: col = 14 * RND(1) LINE (X0, Y0)-(X, Y), col LOCATE 10, 1 PRINT T WEND END ErrTrap: 'if there are errors then quit CLS PRINT "This error requires graphics card VGA" PRINT "Error running program" PRINT "Press any key ...'" WHILE INKEY$ = "" WEND END SUB CenterPrint (Text$) ' Print text centered in 80 column screen offset = 41 - LEN(Text$) \ 2 IF offset < 1 THEN offset = 1 LOCATE , offset PRINT Text$ '\end{verbatim} END SUB