This page suffered its most recent editing hack job on 09-JAN-2003.
This started out as a web page that I had elsewhere, but since it seems that lots of "calculatory folks" also have a fondness for the old pocket computers of the 1980's, I've drug it over here. I had tweaked the code a teeny tiny bit since the original, but decided to leave it the way it was on this page. The tweak only made use of the additional array element that is available in PC-1600 Basic after a DIM statement. In PC-1600 Basic a DIM E(3) means that E(0), E(1), E2) and E(3) are all valid. My code treats it more like other Basic's and assumes that DIM E(3) means that there are three valid array elements E(0), E(1) and E(2). Since there are only two dimensioned arrays, this only amounts to a handful of wasted bytes. Wasted bytes, enhanced compatibility, whatever...
Here is a graphics polygon fill algorithm optimized for the PC-1600's Pocket Computer Basic. I have been using it in various flavors of hand tuned machine code, x86 assembler, C and Basic for well over a decade. As I write this, it is about seventeen years after the 1986 introduction of the PC-1600. Its myriad of expansion options, analog input capabilities, small size with nice, easy to read characters still provide many opportunities for practical and recreational applications.
This routine creates a tiny x,y stack in two dimensioned arrays. For screens larger than the PC-1600's, increase the stack size. The stack keeps track of fill coordinates that need to be revisited for further processing. The routine has checks to prevent stack "overflow" when dealing with polygons requiring more twists and turns than are able to be kept track on in the designated stack size.
Given a flexible fill algorithm, it is possible to modify the pixel testing code in systems with more than one bit per pixel to accommodate "color ranges" that define pixels that do or don't need filled. I leave this to the intrepid experimenter to pursue on their own.
***
*** --== POLYGON FILL DEMO ==--
*** Calls 30000 to demonstrate the fill.
***
10 CLS
20 LINE(0,0)-(64,18)
30 LINE(64,18)-(53,9)
40 LINE(53,9)-(96,14)
50 LINE(96,14)-(70,20)
60 LINE(70,20)-(145,13)
70 LINE(145,13)-(120,0)
80 LINE(0,27)-(140,18)
90 LINE(140,18)-(120,31)
100 LINE(10,6)-(15,15)
110 LINE(15,15)-(5,15)
120 LINE(5,15)-(10,6)
130 FA=5
140 FB=5
150 FC=1
160 GOSUB 30000
170 END
***
*** Sharp PC-1600 POLYGON FILL - FA=X FB=Y FC=Color
*** For the Sharp PC-1600 Pocket Computer. ***
*** To call:
*** - Set FA = X coordinate of initial fill position.
*** ---Range is from 0 --> 155.
*** ---Out of range requests will be ignored.
*** -Set FB = Y coordinate of initial fill position.
*** ---Range is from 0 --> 31.
*** ---Out of range requests will be ignored.
*** -Set FC = Color value used for fill.
*** ---0 or Even values yield white (Like a CLS).
*** ---1 or Odd values yield black (Like text).
*** -After setting FA, FB, FC:
*** ---GOSUB 30000
*** -The contents of FA, FB, FC are unaffected.
***
30000 IF FA<0 OR FA>155 THEN 30025
30001 IF FB<0 OR FB>31 THEN 30025
30002 FD=POINT(FA,FB):FK=ABS(FC) MOD 2
30003 IF FD=FK THEN 30025
30004 DIM FL$(255)*1
30005 DIM FM$(255)*1
30006 FL$(0)=CHR$(FA):FM$(0)=CHR$(FB):FE=1
30007 IF FE<1 OR FE>254 THEN 30025
30008 FE=FE-1:FF=ASC(FL$(FE)):FG=ASC(FM$(FE))
30009 IF FF<1 OR POINT(FF-1,FG)<>FD THEN 30011
30010 FF=FF-1:GOTO 30009
30011 FH=0:FI=0
30012 IF FF>155 OR POINT(FF,FG)<>FD THEN 30024
30013 IF FK=1 THEN PSET(FF,FG) ELSE PRESET(FF,FG)
30014 IF FG>30 THEN 30018 ELSE LET FJ=POINT(FF,FG+1)
30015 IF FJ<>FD OR FH=1 THEN 30017
30016 FL$(FE)=CHR$(FF):FM$(FE)=CHR$(FG+1):FE=FE+1:FH=1
30017 IF FJ<>FD THEN LET FH=0
30018 IF FG<1 THEN 30022 ELSE LET FJ=POINT(FF,FG-1)
30019 IF FJ<>FD OR FI=1 THEN 30021
30020 FL$(FE)=CHR$(FF):FM$(FE)=CHR$(FG-1):FE=FE+1:FI=1
30021 IF FJ<>FD THEN LET FI=0
30022 IF FF<155 THEN LET FF=FF+1
30023 GOTO 30012
30024 GOTO 30007
30025 ERASE FD,FE,FF,FG,FH,FI,FJ,FK,FL$(),FM$():RETURN
There are other folks out there with similar interests. A good place to look is the Sharp Users Club, a UK based club with members all over the world. Take a look at their web site by pointing your browser to: Sharp Users Club