當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Python Wand circle()用法及代碼示例


circle()函數是Wand中的另一個繪圖函數。此方法用於在圖像中繪製圓。它僅需要兩個參數,即圓的原點和周長。

用法: wand.drawing.circle(origin, perimeter)

參數:

參數 輸入類型 描述
origin (collections.abc.Sequence)或(實數,數字。實數) 表示圓的原點x和y的一對。
perimeter (collections.abc.Sequence)或(實數,數字。實數) 對,代表圓的周長x和y

範例1:

# 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, 50) 
  
    # draw circle using circle() function 
    draw.circle(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 ='circle.png')

輸出:



範例2:
輸入圖片:

# 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:
    origin = (100, 100) 
    perimeter = (50, 50) 
  
    # 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') 
  
    # draw bezier curve using bezier function 
    draw.circle(origin, perimeter) 
    with Image(filename ="gog.png") as img:
  
        # draw shape on image using draw() function 
        draw.draw(img) 
        img.save(filename ='circle2.png')

輸出:




相關用法


注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 Wand circle() function in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。