如何使用Turtle在Python中绘制此图?抱歉,这是新手

问题描述

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

外观应类似于提供的图像。了解代码部分,并使其适应您的需求。