📜  Python中的魔杖椭圆()函数

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

Python中的魔杖椭圆()函数

ellipse()函数用于在图像上绘制椭圆。就像画圆一样,ellipse()函数需要两对点,即原点和一对椭圆的 (x, y) 半径。要绘制偏椭圆,请提供一对起始度和终止度作为第三个参数。

示例 #1:

Python3
wand.drawing.ellipse(origin, radius, rotation)


Python3
# Import required objects from wand modules
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
 
# generate object for wand.drawing
with Drawing() as draw:
    # set stroke color
    draw.stroke_color = Color('black')
 
    # set width for stroke
    draw.stroke_width = 1
 
    # fill white color in arc
    draw.fill_color = Color('white')
    origin = (100, 100)
    perimeter = (50, 100)
 
    # draw circle using circle() function
    draw.ellipse(origin, perimeter)
    with Image(width = 200,
               height = 200,
               background = Color('green')) as img:
        # draw shape on image using draw() function
        draw.draw(img)
        img.save(filename ='ellipse.png')


输出 :

示例 #2:使用旋转参数绘制部分椭圆

Python3

# Import required objects from wand modules
from wand.image import Image
from wand.drawing import Drawing
from wand.color import Color
 
# generate object for wand.drawing
with Drawing() as draw:
    # set stroke color
    draw.stroke_color = Color('black')
 
    # set width for stroke
    draw.stroke_width = 1
 
    # fill white color in arc
    draw.fill_color = Color('white')
    origin = (100, 100)
    perimeter = (100, 50)
    rotation = (0, 270)
 
    # draw circle using circle() function
    draw.ellipse(origin, perimeter, rotation)
    with Image(width = 200,
               height = 200,
               background = Color('green')) as img:
        # draw shape on image using draw() function
        draw.draw(img)
        img.save(filename ='ellipsepartial.png')

输出 :