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


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


path_curve_to_quadratic_bezier()繪製從當前點到給定坐標的二次Bezier曲線。如果smooth為True,則假定控製點是上一個命令的控製點的反射,否則必須給出一對控製坐標。

用法: wand.drawing.path_curve_to_quadratic_bezier(to, controls, smooth, relative)
參數 輸入類型 描述
to 序列或(數字。實數,數字。實數) 代表要繪製到的坐標的一對。
control collections.abc.sequence或(numbers.Real,numbers.Real) 用於影響曲線的坐標
smooth bool 假設最後定義的控製坐標
relative bool 將給定的坐標視為相對於當前點。

範例1:

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() 
    # points list to determine curve  
    points = [(40, 10), # Start point  
              (20, 50), # First control  
              (90, 10), # Second control  
              (70, 40)] # End point 
    # Start middle-left 
    draw.path_move(to =(10, 100)) 
    # Curve accross top-left to center 
    draw.path_curve_to_quadratic_bezier(to =(100, 0), 
                    control = points, 
                    smooth = True, 
                    relative = True) 
    draw.path_finish() 
    with Image(width = 200,  
               height = 200,  
               background = Color('lightgreen')) as image:
        draw(image) 
        image.save(filename ="pathbcurve.png")

輸出:

範例2:



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=(100, 100)) 
    # Curve accross top-left to center 
    draw.path_curve_to_quadratic_bezier(to=(100, 0), 
                                        control=[(20,50),(90,10)], 
                                        smooth=True,relative=True) 
      
    draw.path_finish() 
    with Image(width=200, height=200, background=Color('lightgreen')) as image:
        draw(image) 
        image.save(filename="pathbcurve.png")

輸出:

相關用法


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