from turtle import *
setup()
x = 200
# Use your own value
y = 200
# Use your own value
def circles (radius, colour):
penup()
pencolor (colour)
goto (0,radius)
pendown ()
setheading (180)
circle (radius)
penup()
circles (100, "red")
circles (50, "yellow")
circles (25, "green")
def hexagon (size_length):
pendown ()
forward(size_length)
right (60)
goto (x, y)
for _ in range (6):
hexagon (50)
exitonclick ()
一个很好的方法就是用参数定义一个圆,然后使用你想要的。另外,由于六边形是重复的,所以可以使用for循环来构造它的许多边。我就是这样解决的。
有了这个,你不必一直定义圆,只需添加自己的参数,就可以轻松地完成一个for循环。
相关问题 更多 >
编程相关推荐