Question

If I have a QuadCurve like this (+ = node):

+         +
 \      ./
   +--⁻⁻

And I fill it in Java 2D the result is something like this: (x = colored)

+xxxxxxxxx+
 \xxxxxx./
   +--⁻⁻

But I want to color the other side:

+         +
x\      ./x
xxx +--⁻⁻xx
xxxxxxxxxxx

This succeeds by drawing a rectangle around the curve in the color I want to color the other side and then fill the curve with the background color.

But this isn't good enough to fill a convex rounded (based on QuadCurves) polygon. In case of some coordinates for the rectangles (as explained in the trick I used) overlap other pieces of the polygon. Here are two images (the green area is my polygon):

alt text http://img204.imageshack.us/img204/7823/convexpolygon.png alt text http://img708.imageshack.us/img708/3669/convexpolygon2.png

So, the question is simple: "How can I color a shape build of curves?"
But to the answer will not be simple I think...

Any advice would be VERY VERY appreciated.
Thanks in advance.

Maybe I'm going to make a bounty for this question if I don't get an answer

Was it helpful?

Solution

Pick a point known to be inside the Polygon.

Know the "boundary color" (in this case, black).

recurrsiveFill(Pixel p, Color fill, Color bound) {
    p.setColor(fill);
    if(p.left.color  != bound && p.left.color != fill) 
        recurrsiveFill(p.left , fill, bound);
    if(p.right.color != bound && p.right.color != fill) 
        recurrsiveFill(p.right, fill, bound);
    if(p.up.color    != boun d&& p.up.color    != fill) 
        recurrsiveFill(p.up,    fill, bound);
    if(p.down.color  != bound && p.down.color  != fill) 
        recurrsiveFill(p.down,  fill, bound);
}

You can adapt this as necessary to suit your specific needs.

This works for any fill for a completely bounded shape. You'll also want to incorporate special conditions (edges of the picture, for example).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top