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


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


bezier()是Wand中的另一個繪圖函數。此方法用於繪製貝塞爾曲線。它需要四個點才能確定貝塞爾曲線。極限點定義曲線的起點和終點,而在兩個點之間則用於控製曲線。

用法: wand.drawing.bezier(points)
參數:
參數 輸入類型 描述
points list 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
  
    # points list to determine curve 
    points = [(40, 10), # Start point 
              (20, 50), # First control 
              (90, 10), # Second control 
              (70, 40)] # End point  
  
    # fill white color in arc 
    draw.fill_color = Color('white') 
  
    # draw bezier curve using bezier function 
    draw.bezier(points)  
    with Image(width = 100, 
               height = 100, 
               background = Color('green')) as img:
  
        # draw shape on image using draw() function 
        draw.draw(img) 
        img.save(filename ='bezier.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:
    points = [(20, 100),  # Start point 
              (50, 10),  # First control 
              (50, 90),  # Second control 
              (180, 100)] 
  
    # 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 
    # From bottom left around to top right 
    draw.bezier(points)  
    with Image(filename ="gog.png") as img:
  
        # draw shape on image using draw() function 
        draw.draw(img) 
        img.save(filename ='bezier2.png')

輸出:




相關用法


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