[cairo] New user question. How do I fill inside of a curve?
Jody Winston
josephwinston at mac.com
Wed Jan 2 11:06:20 PST 2008
I have a curve that I would like to have one fill color for the positive
half and another fill color for the negative side. In other words, draw
a curve, draw a horizontal line at y = 0, fill everything above 0 with
one color and below with another color.
I'm able to clip the curve but I do not seem to be able to fill the
resulted curve.
Assume that the curve's points are (-100, -100), (100, 100), (200,
-200), (300, 300). For simplicity's sake, only consider the positive
side. The approach that I was trying (and failing) was to construct a
rectangle using cairo_rectangle(cr, -100 ,0, 400, 300), clipping, then
drawing the curve. This approach clips but does not fill. What am I
missing?
Here's a snippet of the problem in Python:
def sawToothPath(context):
context.move_to(-100, -100)
context.line_to(100, 100)
context.move_to(100, 100)
context.line_to(200, -200)
context.move_to(200, -200)
context.line_to(300, 300)
context.stroke()
def sawTooth(context):
context.set_source_rgb(0, 0, 1)
context.save()
context.save()
context.rectangle(-100, 0, 400, 300)
context.set_source_rgb(1, 0, 0)
context.restore()
context.clip()
sawToothPath()
context.set_fill_rule(cairo.FILL_RULE_WINDING)
context.fill()
context.restore()
return
More information about the cairo
mailing list