gpt4 book ai didi

python - turtle graphics ,画个星星?

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:07 25 4
gpt4 key购买 nike

我想画一个填充的星星,比如:

http://www.seaviewstickers.co.uk/shop/media/catalog/product/cache/1/thumbnail/600x600/9df78eab33525d08d6e5fb8d27136e95/b/l/black_11.jpg

到目前为止我有这段代码:

def draw_star(size,color):
count = 0
angle = 144
while count <= 5:
turtle.forward(size)
turtle.right(angle)
count += 1
return

draw_star(100,"purple")

我想用函数传递的任何颜色填充星号。我该怎么做?

最佳答案

要获得 5 角星,您应该在每一侧画 2 条线。角度需要加起来为 72 (360/5)

import turtle
def draw_star(size, color):
angle = 120
turtle.fillcolor(color)
turtle.begin_fill()

for side in range(5):
turtle.forward(size)
turtle.right(angle)
turtle.forward(size)
turtle.right(72 - angle)
turtle.end_fill()
return

draw_star(100, "purple")

尝试不同的angle值以获得你想要的形状

关于python - turtle graphics ,画个星星?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26356543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com