如何与pycairo合并路径?

时间:2018-12-25 23:33:40

标签: python cairo pycairo

我正在使用curve_to与 pycairo 进行绘图,这是代码:

ctx.move_to(0.4,0.8)
ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.8)
ctx.line_to(0.5,0.8)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()


ctx.move_to(0.5,0.8)
ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.fill()

ctx.move_to(0.4,0.4)
ctx.line_to(0.5,0.4)
ctx.set_source_rgb(0,0,0)
ctx.set_line_width(0.001)
ctx.stroke()

enter image description here

我想填充对象,但是如您所见,我无法全部填充,因为它们是分开的并且尚未合并。所以我认为这里最接近的方法是将它们合并。

1 个答案:

答案 0 :(得分:1)

那又怎么样:

    ctx.set_source_rgb(0,0,0)
    ctx.set_line_width(0.001)

    ctx.move_to(0.5,0.8)
    ctx.line_to(0.4,0.8)
    ctx.curve_to(0.3,0.4 ,0.4,0.4 ,0.4,0.4)

    ctx.move_to(0.4,0.4)
    ctx.line_to(0.5,0.8)
    ctx.curve_to(0.6,0.4 ,0.5,0.4 ,0.5,0.4)

    ctx.fill()

我对此进行了测试,并形成了填充区域。我不确定它是否正确。

相关问题