5 Replies Latest reply on Mar 6, 2014 4:03 PM by kglad

    Polygon fill on BitmapData (AS2)

    prodigalmaster Level 2

      Hello.

       

      I know there is floodFill and rectFill, but is there some type of polygonFill class anywhere?

       

      Does anyone know how about I would go about creating it?

        • 1. Re: Polygon fill on BitmapData (AS2)
          kglad Adobe Community Professional & MVP

          what are you trying to do?

          • 2. Re: Polygon fill on BitmapData (AS2)
            prodigalmaster Level 2

            Fill a bitmap circle.

            However, being able to fill a triangle is sufficient, e.g. you define the 3 x, y positions and the colour, and regardless of the pixels within the triangle, they all get set to the colour chosen for the fill.

             

            Using floodfill causes a couple of problems with filling the circle.

             

            Basically, I draw the outline of the circle on the BitmapData, and then if for example you floodfill the middle of the circle, it doesn't neccisarily fill the entire circle if there are pixels blocking the floodfill path of the entire circle (if that makes sense)... so what I do is make another circle but slightly smaller and inside the big circle and instead of use setPixel for all of the pixels in that smaller circle, use floodfill for each x,y position and then do this with another smaller circle, this ensures in most cases the entire circle is filled. It is quite hackish and causes problems. The main problem is that it is inefficient because a floodfill algorithm is used sometimes hundreds of times for the one operation of creating a circle. The second is the outside circle must be sealed completely or the fill moves through the circle to the outside, meaning the outside circle requires as many pixels are possible. Whereas if each iteration of some loop you fill a triangle using the two x,y coordinates of the outside of the circle, and the x,y of the middle of the circle, the outside vertices can be controlled much more easily, and basically makes the entire thing more flexible.

            • 3. Re: Polygon fill on BitmapData (AS2)
              kglad Adobe Community Professional & MVP

              why not use the movieclip linestyle etc methods to create a circle/triangle and use the bitmapdata draw method to create your bitmapdata.

              • 4. Re: Polygon fill on BitmapData (AS2)
                prodigalmaster Level 2

                Aha. Earlier I used the linestyle thing to make a vector version but did not know about the bitmapdata draw method - I assume it converts the drawn vector to bitmap. Hmm that's pretty obvious. I will try to get that working.

                 

                Thanks.

                • 5. Re: Polygon fill on BitmapData (AS2)
                  kglad Adobe Community Professional & MVP

                  you're welcome.