Path: republic.btigate.com!news-xfer.netaxs.com!feeder.qis.net!news-peer.gip.net!news.gsl.net!gip.net!portc01.blue.aol.com!audrey03.news.aol.com!not-for-mail
From: wndalouise@aol.com (WndaLouise)
Newsgroups: comp.sys.hp48
Subject: Re: Filled polygon
Lines: 481
Message-ID: <1998061021395900.RAA24603@ladder03.news.aol.com>
NNTP-Posting-Host: ladder03.news.aol.com
X-Admin: news@aol.com
Date: 10 Jun 1998 21:39:59 GMT
Organization: AOL http://www.aol.com
References: <6lmohv$cpl$1@venus.uvsq.fr>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
Xref: republic.btigate.com comp.sys.hp48:11820

Dang-Ngox wonders:

Could someone tell me how to draw a filled polygon (not by a "dumb algorithm"
like scanning every plot [pixel] and determining wether they must be draw or
not)
and did someone has already implemented on HP48 ?

unfortunately, this is the ONLY (?) way to do it...
( all magick is merely hidden technology )
but the program below does is VERY quickly...

IMPORTANT NOTICE AND POSSIBLE WARNING...???

All of the Programs below were created and used with the 'SX' Variety of  the
48... if you have a 'GX' or 'G' and would like to try them, i would very much
appreciated it if you got back to me and let me know if you have any problems
with them...

All the programs, save one, are written in user code, so that they shouldn't
cause any problems...
But the Nut of the Directory is 'MFIL' which will fill an area on PICT with
Black.  It was written in Machine Code and is VERY fast, about as fast as a
Fill routine on an old Atari Computer...???

This Program MFIL is writtin an SX and GX versions...!!!
BE SURE AND USE THE CORRECT VERSION FOR YOU CALCULATOR...!!!

With this as the jumping off point, i've written several programs to use this
so that you can fill an enclosed or defined area with Black, White, or
Patterns.
Once the usefullness of this Clicks in your head, you'll realise what a
powerful tool MFIL and the accompanying programs can be...

-------------------------------
Fill Directory 
MFIL by Paul Oelund
Support Programs by Wanda Louise
-------------------------------

Fill 
( put this on a User Key )
This is Intended as a catch all for the two primary functions of MFIL and
those are:
1- To fill an area on PICT with Solid Black
&/or
2- To fill an area on PICT with a Pattern.
Fill is designed with the Idiot in mind... 
Such that Input for filling an area with Black,
Is simply a Single, or List of, Complex (x,y) Number(s) on the stack, that
represents a coordinate within an Area on PICT that the User desires to be
Filled. 
-Or-
To Fill an Area with a Pattern, 
The Input is a GROB Section of the desired Pattern & a Complex Number(s) within
the Area to be Filled.  The two elements may be in either order, GROB & Complex
Number(s) or Complex Number(s) & GROB- thus leaving the User the option of
forgetting what the correct arrangement is supposed to be.
1:       Complex Number
or
1:       List of Complex Numbers
or
2:       GROB Pattern
1:       Complex Number or List Thereof
or 
2:       Complex Number or List Thereof
1:       GROB Pattern

For the Area to be Filled with Black, 
Any Object on 2: cannot be a GROB.
-------------------------------
Concerning Patterns
( As for Patterns that can be used with this Directory, 
It comes equipped with a CST that has several choices; 
PreFormated for use. 
Simply Hit a desired CST key and a GROB Section will be brought to the stack.
At the very end of the Custom Menu is a Program called Ofset which takes a
GROB element and recreates it as a Wall Paper Design Section...???
Input is:
1:       GROB
or 
2:       GROB
1:       y Gap
With the y Gap being the number of pixels that The Rows will be separated from
one another by...
Default ( Input option 1 ) is zero.
The Value may be either Positive or Negative.)
-------------------------------


Filb
Fill an Area on Pict with Black
Input is:
1:       Complex Number that represents a coordinate on PICT.
or
1:       List of Complex Numbers...

Filb(dot)
Fill a Defined Polygon on Pict with Black
Input is:
1:       List of Complex Numbers that Define a Single, Mostly Convex Polygon on
PICT.

Filp
Fill an Area on PICT with a Pattern
Works very much like Filb, except that the Input is:
2:       Patterned GROB Section
1:       Single Complex Number Or List of Complex Numbers

Filp(dot)
Fill a Defined Polygon on PICT with a Pattern
The way this one works is a little more Sophisticated than Filb, in that this
will OverWrite the area under the newly created Polygon.
Input is:
2:       Patterned GROB Section
1:       List of Complex Points that Define a Single, Mostly Convex Polygon on
PICT.

Filw(dot)
Create an All White Polygon on PICT.
Input is:
1:       List of Complex Points that Define a Single, Mostly Convex Polygon on
PICT.

Ptrn
Takes a GROB with Black Regions on it, and converts those Regions to a Chosen
Pattern.
Input is:
2:       GROB with Black Region(s)
1:       Patterned GROB Section
or
3:       GROB with Black Region(s)
2:       Patterned GROB Section 
1:       1
In this Later Case, The Regions that will Receive the Desired Pattern will also
be OutLined.

Hue
Hue simply fills an Area Defined by a GROB with a Given Pattern. 
2:       GROB that will be Entirely Filled with a Pattern.
1:       Patterned GROB Section

Outl
Connects a Collection of Points to Form an Enclosed Polygon.
Input is:
1:       List of Complex Numbers that Define a Polygon

MFIL   CheckSum # E661h
The Nut of this Directory is a Machine Code Routine written by Paul Oelund-
roughly based on a User-RPL Program written by me.
It simply fills a area on PICT with Black, given a Starting Coordinate.
Input is:
1:       Complex Number that Refers to a Coordinate on PICT
or a
1:       Binary { #x #y } Coordinate 
Further, MFIL will return a 1 if everything went well, 
or a 0 if something weird happened, i.e., it was unable to fill any portion of
PICT with Black.

..........................................................................
Below is MFIL by Paul Oelund.
It is encoded with ->ASC and requires ASC-> to Decode it.  the ASC's are
programs written by William Wickes and are available from the Appendix's FAQ's
file, or you can Eep me and i'll send you a copy. 
> TinyWanda@aol.com <
..........................................................................

This is the SX Version...!!!

%%HP: T(3)A(D)F(.);
"D9D2078BF18813068BC19C2A2E2B30CB916971F44B2A2CCD20272008FB97608F
15550808F174D230BE35606370306C3DB10A1471341641C41CEAF0A7C159970A
17C918411B5650714613416914210116414610BAF1A7DAF415B9974E18F2D760
349C2A214580808D3415017411AE6E610A1001198BEFD147174D511B8B9FC7F6
18F2F8310E0090C8911078518A843CC8190190DB018081801715600E0590ABDE
4A0590D80B0516085085211BDE8FA5611DED715600E0D1540136EB1341188AA7
215600E0590A908506410860E084070E0CE145136CBCB134121118E68B690121
6B2012115600E0590A908526410862E08427A90E6145136EB134E4A0590D8016
0B0515600E0590EE011B8BE606B4F698E1C434E4A201428A28007649E164146D
5D2306E1304248B980D980D01641561E5132C014520130018148148148148140
111A818FA1580076A3E10A1C41181411C401B48268DBF1B2130166E"

This is the GX Version...!!!

%%HP: T(3)A(D)F(.);
"D9D2078BF18813068BC19C2A2E2B30CB916971F44B2A2CCD20272008FB97608F
15550808F174D230BE35606370306C3DB10A1471341641C41CEAF0A7C159970A
17C918411B4E60814613416914210116414610BAF1A7DAF415B9974E18F2D760
349C2A214580808D3415017411AE6E610A1001198BEFD147174D511B8B9FC7F6
18F2F8310E0090C8911078518A843CC8190190DB018081801715600E0590ABDE
4A0590D80B0516085085211BDE8FA5611DED715600E0D1540136EB1341188AA7
215600E0590A908506410860E084070E0CE145136CBCB134121118E68B690121
6B2012115600E0590A908526410862E08427A90E6145136EB134E4A0590D8016
0B0515600E0590EE011B8BE606B4F698E1C434E4A201428A28007649E164146D
5D2306E1304248B980D980D01641561E5132C014520130018148148148148140
111A818FA1580076A3E10A1C41181411C401B48268DBF1B213029B6"

..........................................................................
The Fill Directory with a CST of Fun Patterns/minus MFIL which is in Machine
Code:
..........................................................................

%%HP: T(3)A(D)F(.);
DIR
  Fill
    \<< DEPTH 1 >
      \<< DUP TYPE 11
== 3 PICK TYPE 11
== +
      \>> 0 IFTE :&:
Filp :&: Filb IFTE
    \>>
  Filb
    \<< :&: Cpict
EVAL DUP TYPE 5 ==
      \<< OBJ\->
      \>> 1 IFTE 1
SWAP
      START :&:
MFIL EVAL DROP
      NEXT
    \>>
  Filb\183
    \<< DUP :&: Outl
EVAL OBJ\-> DUP DUP 2
+ ROLLD 2 SWAP
      START +
      NEXT SWAP /
:&: Filb EVAL
    \>>
  Filp
    \<< DUP TYPE 11
==
      \<< SWAP
      \>> IFT PICT
RCL DUP SIZE BLANK
4 ROLL :&: Hue EVAL
NEG ROT :&: Filb
EVAL PICT DUP NEG {
# 0d # 0d } DUP2 5
ROLL GOR OVER NEG
ROT GOR
    \>>
  Filp\183
    \<< DUP TYPE 11
==
      \<< SWAP
      \>> IFT :&:
Cpict EVAL CL\GS DUP
OBJ\-> 1 SWAP
      START V\-> 2
\->ARRY \GS+
      NEXT MAX\GS V\->
MIN\GS V\-> OVER 4 PICK
\->V2 SWAP 4 ROLL -
ABS ROT 4 ROLL -
ABS :&: Pxdm EVAL
V\-> 4 ROLL SWAP / 1
+ R\->B SWAP ROT SWAP
/ 1 + R\->B SWAP
BLANK 4 ROLL :&:
Hue EVAL NEG PICT
RCL NEG ERASE 4
PICK DUP :&: Outl
EVAL OBJ\-> DUP DUP 2
+ ROLLD 2 SWAP
      START +
      NEXT SWAP /
:&: Filb EVAL PPAR
1 2 SUB EVAL DUP2
V\-> ROT V\-> 4 ROLL
SWAP \->V2 PIX? SWAP
ROT \->V2 PIX? + SWAP
PIX? + SWAP PIX? +
2 >
      \<< PICT NEG
      \>> IFT PICT
RCL + NEG PICT NEG
3 ROLLD { GOR } :&:
Grbr EVAL PICT DUP
NEG { # 0d # 0d }
ROT GOR :&: Outl
EVAL CL\GS
    \>>
  Filw\183
    \<< PICT RCL NEG
ERASE OVER :&:
Filb\183 EVAL PPAR 1 2
SUB EVAL DUP2 V\->
ROT V\-> 4 ROLL SWAP
R\->C PIX? SWAP ROT
R\->C PIX? + SWAP
PIX? + SWAP PIX? +
2 >
      \<< ERASE
      \>> IFT PICT {
# 0d # 0d } ROT GOR
PICT NEG :&: Outl
EVAL
    \>>
  Ptrn
    \<< DUP TYPE NOT
\-> \183
      \<< \183
        \<< DROP
        \>> IFT OVER
SWAP :&: Hue EVAL
NEG SWAP \183
        \<< DUP :&:
Trace EVAL 3 ROLLD
        \>> IFT NEG +
NEG \183
        \<< { # 1d
# 1d } SWAP GOR
        \>> IFT
      \>>
    \>>
  Hue
    \<< DUP2 SIZE ROT
SIZE \-> p b q d
      \<< { # 0d # 0d
} SWAP REPL
        WHILE p q <
        REPEAT DUP
{ # 0d # 0d } p b 2
\->LIST SUB p { # 0d
} + SWAP REPL 'p' 2
STO*
        END
        WHILE b d <
        REPEAT DUP
{ # 0d # 0d } q b 2
\->LIST SUB { # 0d }
b + SWAP REPL 'b' 2
STO*
        END
      \>>
    \>>
  Outl
    \<< OBJ\-> DUP2 2 +
ROLLD 1 SWAP
      START OVER
LINE
      NEXT DROP
    \>>
  Neg2
    \<< PICT RCL SWAP
ERASE DUP :&: Trace
EVAL DUP SIZE DUP2
2 \->LIST 5 ROLLD 2 +
SWAP 2 + SWAP PDIM
:&: Cpict EVAL PICT
{ # 1d # 1d } ROT
REPL PICT RCL {
# 0d # 0d } PX\->C
:&: Filb EVAL PICT
{ # 0d # 0d } ROT
GXOR PICT { # 2d
# 2d } ROT GOR PICT
NEG PICT RCL { # 1d
# 1d } ROT SUB SWAP
TEXT PICT STO
    \>>
  CST { {
GROB 21 8 101010000000000000000000010101000000000000000000
GROB 8 8 1000000001000000
} {
GROB 21 8 140140000000000000802800000000000000140140000000
GROB 6 6 100000800000
} {
GROB 21 8 111111000000444440000000111111000000444440000000
GROB 4 4 10004000 }
{
GROB 21 8 942940000000429421000000294290000000942940000000
GROB 3 6 100040002000
} {
GROB 21 8 555551AAAAA0555551AAAAA0555551AAAAA0555551AAAAA0
GROB 4 4 50A050A0 }
{
GROB 21 8 000000C1E070E3F9F0E3F9F0E3F9F0C1E0700000001E0781
GROB 14 12 0000C1E0E3F1E3F1E3F1C1E000001E033F933F933F931E03
} {
GROB 21 8 000000070830CF1EF0CF1EF0EF3FF1EF3FF1EF3FF1CF1EF0
GROB 22 20 000000070830CF1EF0CF1EF0EF3FF1EF3FF1EF3FF1CF1EF0CF1EF007083000000010E00378F3C378F3C3FCF7E3FCF7E3FCF7E378F3C378F3C310E003
} {
GROB 21 8 FFF551308FF11B3FF1D17FF1D57FF1140FF1FAEFF1F0EFF1
GROB 20 18 FFF550308FF01B3FF0D17FF0D57FF0140FF0FAEFF0F0EFF070CFF075DFF0EFF000CF7CE0DF77C0DF77D0CF7010FFFBA0FFF380FFF100
} {
GROB 21 8 C5C5C18888805C5C503E3E301D1D11888880D1D1D1E0E0E0
GROB 8 8 C5885C3E1D88D1E3
} {
GROB 21 8 8FF1000EF1000CF3000CF3000C97000C0620140060100060
GROB 18 24 8FF1000EF1000CF3000CF3000C97000C0620140020100020300030F70030F30C30F18F30F00F30F00C30F10830F10830C3083003181000380000300008700008FF000EF700CFF300
} {
GROB 21 8 8F30E18F30E10F10C16EC891F4ED31F0EF30F0EF3070CF10
GROB 14 14 8F308F300F106EC0F4E1F0E3F0E370C370C330839133CB72CF70CF70
} {
GROB 21 8 630630F70F70F70F70E30E30C10C1080080008D0811CF1C1
GROB 12 12 6300F700F700E300C100800008D01CF01CF008F000700020
} {
GROB 21 8 F5F5F1FAFAF0F5F5F1FAFAF0B0B0B0D0D0D0B0B0B0D0D0D0
GROB 8 8 F5FAF5FAB0D0B0D0
} {
GROB 21 8 D6D6D0292921121210D2D2D0292921969690909090292921
GROB 8 8 D62912D229969029
} {
GROB 21 8 0C0C008D8D81B1B1B13030300303011B1B11D8D8D0C0C0C0
GROB 8 8 0C8DB130031BD8C0
} {
GROB 21 8 5DA651BA5DA07DBE51FA7DB0FDFE71FBFDF0FFFFF15DA651
GROB 7 7 55B275F2F5F3F7
} {
GROB 21 8 FD7FD1FD7FD13D43D03D43D0FD7FD1000000FD7FD1FD7FD1
GROB 6 6 F1F13131F100
} {
GROB 21 8 E83E81956950FD7FD1FD7FD1E83E81000000E83E81956950
GROB 6 6 E091F1F1E000
} {
GROB 21 8 4044003E83E08138114044003E83E08138114044003E83E0
GROB 12 3 40403E808130
} {
GROB 21 8 429421A82A80154150429421A82A80154150429421A82A80
GROB 6 3 42A011 } {
GROB 21 8 707070888880070701888880707070888880070701888880
GROB 8 4 70880788 }
{
GROB 21 8 555551555551555551555551555551555551555551555551
GROB 2 1 10 } {
GROB 21 8 FFFFF1000000FFFFF1000000FFFFF1000000FFFFF1000000
GROB 1 2 1000 } {
GROB 21 8 F09F4078F7A039D31192C920446441A802A11D01D18E98E1
GROB 84 12 88688E98E1BE12F9CE98C044F44F44F86F0FF41E41102A72A7CA78C72B72232A101D31D3AD3CF35835401D308E1BE12F9CE98C88688E904F86F0FF41E41144F44F40A78C72B72232A12A72A7C0D3CF35835401D31D31D3A0F9CE98C88688E98E1BE120F41E41144F44F44F86F0F072232A12A72A7CA78C72B035401D31D31D3AD3CF3580
} {
GROB 21 8 000000EECEE0A22240AE4E40A28240E26E40000000000000
    \<< DUP TYPE 11 \=/
      \<< SWAP
      \>>
      \<< 0 SWAP
      \>> IFTE DUP
SIZE \-> v g x y
      \<< x 2 * y 2 *
B\->R v + R\->B BLANK {
# 0d # 0d } g GOR x
# 0d 2 \->LIST g GOR
DUP { # 0d # 0d } x
2 * 1 - y 1 - 2
\->LIST SUB SWAP # 0d
y 2 * B\->R v 2 * +
R\->B 2 \->LIST 3 PICK
        IFERR GOR
        THEN DROP2
        END x 2 / y
B\->R v + R\->B 2 \->LIST
3 PICK GOR SWAP x
B\->R 2 / CEIL R\->B
# 0d 2 \->LIST x 1 -
y 1 - 2 \->LIST SUB
# 0d y B\->R v + R\->B
2 \->LIST SWAP GOR v
SIGN 1 +
        \<< DUP SIZE
v + BLANK # 0d v
R\->B 2 \->LIST ROT
REPL
        \>>
        \<< DUP SIZE
1 - SWAP 1 - SWAP 2
\->LIST # 0d DUP v
NEG + 2 \->LIST SUB
        \>> IFTE
      \>>
    \>> } }
END
