[cairo] New user question. How do I fill inside of a curve?
Bill Spitzak
spitzak at thefoundry.co.uk
Thu Jan 3 11:03:11 PST 2008
Add this to your path to make a closed shape (minx and maxx are the
x coordinate of the first and last points):
lineto(maxx, 0);
lineto(minx, 0);
closepath
If you fill this shape it will fill the areas you want, but all with the
same color.
So you then must draw it twice with two different clip rectangles, one
with the bottom edge at y=0 and the other with it's top edge at y=0.
Alternatively it may be possible to set the source to an image or
gradient to put the correct color in with one fill.
Jody Winston wrote:
> First of all, thanks for the help with my first attempt at Cairo. I
> also am apologizing for munging the email headers by hand but I do not
> have the original email chain with me.
>
> I think that I did everything you suggested and have attached a
> standalone example with your changes, but I still am having problems.
>
> What I am attempting to do is color the area of a curve that either is
> above or below the line y = 0 as quickly as possible since I have a
> large number of these curves to process.
>
> The problem might be best expressed by looking at a contrived example.
> Given a curve defined by [(-100, -100), (100, 100), (200, -200), (300,
> 300)]. I need to color the triangles [(0, 0), (100, 100), (400/3, 0)]
> and [(240, 0), (300, 300), (300, 0)] with one color since they are the
> areas of the curve that are between y = 0 and the curve itself.
> Likewise, I need to color the triangles [(-100, -100), (-100, 0), (0, 0,
> 0)] and [(400/3, 0), (240, 0), (200, -200)] since they are between the
> curve and the line y = 0.
More information about the cairo
mailing list