Announcement

Collapse
No announcement yet.

How to color graphic areas?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to color graphic areas?

    Hi,

    Having drawn areas which are bordered by GRAPHIC LINEs and ARCs I would like to fill these areas with a color.
    So far I have filled parallelograms which is easily done with LINEs between the parallel sides.
    But what can be done with unevenly shaped areas? Does anyone have an idea?

    Rgds, Gert
    Gert Voland

  • #2
    See GRAPHIC PAINT in PB Help. "Purpose: Fill an area with a solid color or a hatch pattern."
    Syntax : GRAPHIC PAINT [BORDER | REPLACE] [STEP] (x!, y!) [, [rgbFill&] [, [rgbBorder&] [, [fillstyle&]]]]

    Comment


    • #3
      If speed is important, and you can draw the boundary explicitly, see Graphic Polygon in the Help.
      Politically incorrect signatures about immigration patriots are forbidden. Searching “immigration patriots” is forbidden. Thinking about searching ... well, don’t even think about it.

      Comment


      • #4
        Thank you all,

        The PAINT command had slipped my mind. I must have thought it applied only to the available standard shapes. I'll give it a try ...
        I assume the POLYGON construction is OK for the parallelograms but not for the ones with arcs as borders.

        Rgds, Gert
        Gert Voland

        Comment


        • #5
          Originally posted by Gert Voland View Post
          Thank you all,
          I assume the POLYGON construction is OK for the parallelograms but not for the ones with arcs as borders.

          Rgds, Gert

          The name is a clue. Not just parallelograms, any straight sided figure.
          A couple of simple definitions.
          "a closed plane figure with straight edges" or "A polygon is a closed two-dimensional figure, that comprises three or more straight lines"

          However, if you really want to get confused: https://mathworld.wolfram.com/Polygon.html



          Comment


          • #6
            . . . but not for the ones with arcs as borders.
            That part is correct.
            Dale

            Comment


            • #7
              The WinAPI GDI function ExtFloodFill() can handle weird enclosed shapes. But I do not know if this command is compatible with the PB "GRAPHICS" family.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                @Stuart,
                Thank you for your kind words. I was only contemplating what to use for my different types of shapes...

                While testing different methods I came across an interesting phenomenon:
                The display showed extra pixels at both sides of a color transition which are not very helpful when you want to check the effect of Graphic Commands on a highly magnified pixel level.

                Knowing that it is not caused by the PB commands, I checked the Graphic driver as well as the 1980 * 1020 HD monitor.
                But no, it is caused by Window's Display Scaling which I had set to 125%.
                Like any resizing routine it interpolates the colors for pixels at the transitions.
                Of course it appears only at the display on screen - no effect on the data behind it.

                There are two ways to get around it and check the effects of algorithms on each single pixel in Photoshop (or similar):
                (a) Switch to 100% scaling. Then a screen shot copied to the clipboard can be used directly, or
                (b) Keep the 125% and copy the GRAPHIC WINDOW hWin to the CLIPBOARD by program.

                Rgds, Gert
                Gert Voland

                Comment


                • #9
                  Originally posted by Michael Mattias View Post
                  The WinAPI GDI function ExtFloodFill() can handle weird enclosed shapes. But I do not know if this command is compatible with the PB "GRAPHICS" family.
                  Thanks Michael.
                  ExtFloodFill() seems to achieve exactly the same as the GRAPHIC PAINT command which probably is just a wrapper.

                  GRAPHIC PAINT passes the device context handle, sets up the brush with the fill color and fill style, uses the border color and scales the PB page unit coordinates to the actual pixel coordinates. BORDER and REPLACE set up the fuFillType flag.
                  As even some of the descriptive wording is the same, I don't think that the API function does more than the PB command.

                  Rgds
                  Gert Voland

                  Comment


                  • #10
                    Gert

                    Old SDK code posted on this forum 17 years ago

                    Linear Floodfill with tolerance
                    https://forum.powerbasic.com/forum/u...erance?t=24427
                    Patrice Terrier
                    www.zapsolution.com
                    www.objreader.com
                    Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                    Comment


                    • #11
                      Hi Patrice,
                      Thank you for posting the link. Yes - time flies ..

                      I would like to fill some areas that are created by overlapping standard shapes:

                      Click image for larger version

Name:	FloodFill1.png
Views:	130
Size:	1.0 KB
ID:	807804
                      At the moment I draw them with a blue border and fill colors at the seed points with GRAPHIC PAINT BORDER.
                      Using the REPLACE option I can only re-color the complete border.

                      How can your routines help?
                      I would like to color the border of each area separately.
                      A function would help, that extends an area by a certain number of pixels outward - and thus replaces (part of) the border.

                      Technically your routines don't work yet with PBCC 6. Some declarations are missing - easy to fix.
                      The functions GetRValue etc. are defined in the Win32Api.inc. And the TYPE COLORLONG is missing.

                      What do you think?
                      Rgds
                      Gert Voland

                      Comment


                      • #12
                        TYPE COLORLONG
                        longval AS LONG
                        END TYPE


                        My thought,, is that you would have better to use GDIPLUS rather than GDI32 to achieve this.

                        You can also have a look on my private forum for my GDplus 64-bit custom project (i do have also a 32-bit PowerBASIC version)
                        that is able to manipulate and resize complex shapes with or without borders, and paint in tiling mode.
                        http://www.objreader.com/index.php?t...sg2289#msg2289

                        About Linear Floodfill with tolerance,
                        the color of the seed point would be replaced by the new color for all the contiguous points (just like in PhotoShop).
                        Patrice Terrier
                        www.zapsolution.com
                        www.objreader.com
                        Addons: GDImage.DLL 32/64-bit (Graphic library), WinLIFT.DLL 32/64-bit (Skin Engine).

                        Comment


                        • #13
                          FWIW, You can use GRAPHIC ARC and GRAPHIC LINE to change the colours of the boundaries in the overlap region. The arc would use the same dimensions as the ellipse with added start and end angles.
                          Rod
                          In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                          Comment


                          • #14
                            Why worry about RE-coloring? It works like an Etch-a-Sketch (r)... whatever you do last is what ends up on top and is what you see.

                            E.G. above picture you draw a red rectangle, then a yellow ellipse and lastly a couple of green pies.
                            Michael Mattias
                            Tal Systems (retired)
                            Port Washington WI USA
                            [email protected]
                            http://www.talsystems.com

                            Comment


                            • #15
                              Thank you for the hints.

                              Yes the ARC or PIE can be used plus a few rectangles to fill the overlap. But that is exactly the problem.
                              For the very simple example above it is possible to calculate the intersecting points and then get the angles.
                              For my other areas that is not generally possible - unless you do complicated pixel searches.

                              In the case of straight borders the POLYGON method works very well because the intersecting points can be calculated - it is "pixel perfect".

                              I'll keep looking ...

                              Rgds
                              Gert Voland

                              Comment


                              • #16
                                You might also try using the 'style' modes associated with GRAPHIC COPY and GRAPHIC STRETCH. Never used them myself, but there might be something that is applicable here.
                                Rod
                                In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                                Comment


                                • #17
                                  Yes, on those lines there could be a rough-and-ready method using rasterisation effects:

                                  - Draw on a much larger bitmap - let's say 5 times in x and y. Coordinates for drawing are increased by that factor, but the minimum line width (1 or 2) is used to do the flood-filling.
                                  - Then copy the bitmap to the 5 times smaller target - and the minimum lines have disappeared.

                                  I see that effect on shapes on 10000 * 10000 bitmaps when they are displayed on the HD screen.
                                  It may be used for one-off projects since it is not a very efficient method and I would like to also use it on the highest resolution ...

                                  Rgds
                                  Gert Voland

                                  Comment


                                  • #18
                                    Originally posted by Rodney Hicks View Post
                                    You might also try using the 'style' modes associated with GRAPHIC COPY and GRAPHIC STRETCH. Never used them myself, but there might be something that is applicable here.
                                    Mix / style modes do seem promising..
                                    '
                                    Code:
                                    #Compile Exe        ' PBCC604 , PBWin1004
                                    #Dim All
                                    #If %Def(%PB_CC32)
                                     #Console Off
                                     #Break On
                                    #EndIf
                                    #Include "win32api.inc"
                                     
                                    #If %Def(%PB_Win32)
                                      Macro StdOut = MsgBox
                                    #EndIf
                                    '------------------/
                                     
                                    Function PBMain () As Long
                                    LOCAL hWin, hElipse, hBox AS DWORD
                                     
                                     GRAPHIC WINDOW "Paint", 200, 200, 350, 330 TO hWin
                                     GRAPHIC ATTACH hWin, 0
                                     ' Draw a circle with green foreground color
                                     GRAPHIC BITMAP NEW 350, 330 To hElipse
                                     GRAPHIC ATTACH hElipse, 0
                                     GRAPHIC CLEAR %RGB_LIGHTGRAY
                                     GRAPHIC ELLIPSE (10, 20) - (210, 170), %RGB_GREEN, -1, 0
                                     
                                     ' and a box below it with red foreground color.
                                     GRAPHIC BITMAP NEW 350, 330 To hBox
                                     GRAPHIC ATTACH hBox, 0
                                     GRAPHIC CLEAR %RGB_LIGHTGRAY
                                     GRAPHIC BOX (60, 70) - (310, 270), 0, %RGB_RED, -1, 0
                                     ' copy elipse to Graphic target
                                     GRAPHIC ATTACH hWin, 0
                                     
                                     GRAPHIC COPY hElipse, 0, %mix_MaskSrc
                                       SLEEP 2000
                                     GRAPHIC COPY hBox, 0, %mix_MaskSrc
                                       SLEEP 2000
                                     GRAPHIC PAINT REPLACE (100,100), %RGB_YELLOW, %RGB_BLACK
                                       SLEEP 8000
                                     
                                    #If %Def(%PB_CC32)
                                      If Con.Handle Then
                                        ? "Any key to exit"
                                        WaitKey$
                                      End If
                                     #EndIf
                                    End Function
                                    '------------------/PBMain
                                    Click image for larger version

Name:	mix_MaskSrc.PNG
Views:	102
Size:	7.0 KB
ID:	807857
                                    Rgds, Dave

                                    Comment


                                    • #19
                                      Dave,
                                      Great, this works well. The trick is the %mix_MaskSrc equate leaving the overlap black.
                                      I never used the COPY equates, partly because their function wasn't clear.
                                      Rgds
                                      Gert Voland

                                      Comment

                                      Working...
                                      X