如何使用 turtle 在 Python 中绘制此图形?对不起,新来的
How can I draw this figure in Python using turtle? Sorry, new to this
enter image description here
嗨,我正在尝试使用 Python 乌龟为学习小组绘制这个形状,但我完全迷路了。请帮忙
尝试从将其添加到文件开始firsttry.py
import turtle, random
basiclength = 10
elementspercircle = 12
colors = ["red","green","blue","orange","purple","pink","yellow"]
length = basiclength
angle = 360/elementspercircle
turtle.pensize(5)
def paintingpainter(directionoffset):
global length
global angle
global colors
for j in range (4):
for i in range( elementspercircle + 1):
turtle.color(random.choice(colors))
turtle.forward(length)
turtle.left(angle * directionoffset)
length = length + directionoffset
paintingpainter(1)
turtle.right(angle * 2)
paintingpainter(-1)
然后从
开始
python3 firsttry.py
看起来应该与提供的图片相似。了解代码部分并根据您的需要进行调整。
enter image description here
嗨,我正在尝试使用 Python 乌龟为学习小组绘制这个形状,但我完全迷路了。请帮忙
尝试从将其添加到文件开始firsttry.py
import turtle, random
basiclength = 10
elementspercircle = 12
colors = ["red","green","blue","orange","purple","pink","yellow"]
length = basiclength
angle = 360/elementspercircle
turtle.pensize(5)
def paintingpainter(directionoffset):
global length
global angle
global colors
for j in range (4):
for i in range( elementspercircle + 1):
turtle.color(random.choice(colors))
turtle.forward(length)
turtle.left(angle * directionoffset)
length = length + directionoffset
paintingpainter(1)
turtle.right(angle * 2)
paintingpainter(-1)
然后从
开始python3 firsttry.py
看起来应该与提供的图片相似。了解代码部分并根据您的需要进行调整。