python畫一個簡單的五角星或者多邊形
阿新 • • 發佈:2019-02-04
首先,我們需要確定五個角的座標, #繪製多邊形 from tkinter import * import math as m root = Tk() w = Canvas(root,width=200,height=150,background="red") w.pack() center_x = 100 center_y = 70 r=50 points =[ #左上點 center_x - int(r * m.sin(2 * m.pi / 5)), center_y - int(r * m.cos(2 * m.pi / 5)), # 右上點 center_x + int(r * m.sin(2 * m.pi / 5)), center_y - int(r * m.cos(2 * m.pi / 5)), # 左下點 # center_x - int(r * m.sin(m.pi / 5)), # center_y + int(r * m.cos(m.pi / 5)), center_x - int(r * m.sin(m.pi / 5)), center_y + int(r * m.cos(m.pi / 5)), # 頂點 center_x, center_y - r, #右下點 center_x + int(r * m.sin(m.pi / 5)), center_y + int(r * m.cos(m.pi / 5)), ] w.create_polygon(points,outline="green",fill="yellow") mainloop() 執行效果圖