python中怎么把五角星画在中间

在python中怎么把五角星画在屏幕的中间?
2025-04-09 20:36:08
推荐回答(2个)
回答1:

from turtle import *
fillcolor("red")
begin_fill()
while True:
    forward(200)
    right(144)
    if abs(pos()) < 1:
        break
end_fill()

运行这段代码,会绘制出一个红色五角星图形。

码字不易,望采纳。

回答2:

from tkinter import *
import math
base=Tk()
canvas=Canvas(base,width=1000,height=800,background='grey')
canvas.pack()
center_x=500
center_y=400
r=200
points=[
    center_x-int(r*math.sin(2*math.pi/5)),
    center_y-int(r*math.cos(2*math.pi/5)),
    center_x+int(r*math.sin(2*math.pi/5)),
    center_y-int(r*math.cos(2*math.pi/5)),
    center_x-int(r*math.sin(math.pi/5)),
    center_y+int(r*math.cos(math.pi/5)),
    center_x,
    center_y-r,
    center_x+int(r*math.sin(math.pi/5)),
    center_y+int(r*math.cos(math.pi/5)),
]
canvas.create_polygon(points,outline='green',fill='yellow')
base.mainloop()

五角星倒是好画,win屏幕上难,要使用win32屏幕绘图吧