📜  Python中的魔杖path_close()函数

📅  最后修改于: 2022-05-13 01:55:04.125000             🧑  作者: Mango

Python中的魔杖path_close()函数

path_move()是 wand 中包含的另一个用于路径的函数。此函数的主要目的是将最后一个目标点连接到路径中的第一个点。它只是向当前路径添加一个路径元素,通过从当前点到当前子路径的最近起点绘制一条直线来关闭当前子路径。

代码 :

Python3
# importing wand
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
 
with Drawing() as draw:
    draw.stroke_width = 2
    draw.stroke_color = Color('black')
    draw.fill_color = Color('white')
    draw.path_start()
    # Start middle-left
    draw.path_move(to =(10, 100))
    # Curve across top-left to center
    draw.path_curve(to =(80, 0),
                    controls =[(20, -80), (60, -80)],
                    relative = True)
    # Continue curve across bottom-right
    draw.path_curve(to =(80, 0),
                    controls =(60, 80),
                    smooth = True,
                    relative = True)
    # Join the last destination point to the first point
    draw.path_close()
    draw.path_finish()
    with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
        draw(image)
        image.save(filename = "pathclose.png")


输出: