A Recursive Fill Routine in Classic BASIC
|
|
|
BASIC
EDIT F1
CAPS LOCK F2
LEFT F5, SHIFT+LEFT
DOWN F6, SHIFT+DOWN
UP F7, SHIFT+UP
RIGHT F8, SHIFT+RIGHT
GRAPHICS MODE F9
Click on the Screen and enter 'run' for another go.
Click here to continue the tour of ZX BASIC programs.
|
The Jasper ZX Spectrum emulator running a BASIC Fill Demonstration
The same algorithm used in the Chess problems is demostrated here in
a simple shape filling routine written in Sinclair BASIC using recursion
and backtracking.
This fine example comes from the BASin development system by Paul Dunn
with which many of these examples have been refined.
A BASIC FILL ROUTINE - an example of recursion in BASIC.
5 CLS : PRINT TAB 5;"BASIC RECURSIVE FILL"
10 CIRCLE 128,88,40: CIRCLE 128,88,30
20 LET x=100: LET y=100
30 GO SUB 1000: STOP
1000 PLOT x,y
1010 IF NOT POINT (x+1,y) THEN LET x=x+1: GO SUB 1000: LET x=x-1
1020 IF NOT POINT (x-1,y) THEN LET x=x-1: GO SUB 1000: LET x=x+1
1030 IF NOT POINT (x,y+1) THEN LET y=y+1: GO SUB 1000: LET y=y-1
1040 IF NOT POINT (x,y-1) THEN LET y=y-1: GO SUB 1000: LET y=y+1
1050 RETURN