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


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


polyline()是Wand的wand.drawing模塊中存在的另一個繪圖函數。 polyline()與polygon()函數相似,唯一的區別是,它不會關閉筆劃線的第一個和最後一個點。與polygon()相似,它也使用點元組列表作為參數。

用法:
wand.drawing.polyline(points)

參數:

參數 輸入類型 描述
points list x,y元組的列表。

例子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') 
  
    # points list for polygon 
    points = [(25, 25), (175, 100), (25, 175)] 
  
    # draw polygon using polygon() function 
    draw.polyline(points) 
    with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
        draw(image) 
        image.save(filename = "polygon.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') 
  
    # points list for polygon 
    points = [(25, 150), (50, 50), (150, 50), (175, 150)] 
  
    # draw polygon using polygon() function 
    draw.polyline(points) 
    with Image(width = 200, height = 200, background = Color('lightgreen')) as image:
        draw(image) 
        image.save(filename = "polyline2.png")

輸出:




相關用法


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