【发布时间】:2019-07-21 19:35:11
【问题描述】:
我想使用turtle 制作这张图片,
这是我目前的情况,但有多个错误。
import turtle
import colorsys
import random
def draw_circle(x,y,r,color):
turtle.up()
turtle.seth(0)
turtle.goto(x,y-r)
turtle.down()
turtle.fillcolor(color)
turtle.begin_fill()
turtle.circle(r)
turtle.end_fill()
def draw_square(x,y):
turtle.up()
turtle.seth(0)
turtle.goto(x,y)
turtle.fillcolor(color)
turtle.pencolor(color)
turtle.down()
turtle.begin_fill()
for i in range(2):
turtle.fd(w)
turtle.left(90)
turtle.fd(h)
turtle.left(90)
turtle.end_fill()
turtle.speed(0)
x = 0
y = -200
for i in range(100):
color = colorsys.hsv_to_rgb(x,1,1)
turtle.pencolor(color)
draw_square(x,y)
x += .01
y += 10
我收到此错误:
Traceback (most recent call last):
File "/Users/MBach/Documents/concentric squares.py", line 39, in <module>
draw_square(x,y)
File "/Users/MBach/Documents/concentric squares.py", line 24, in draw_square
turtle.fd(w)
NameError: name 'w' is not defined
>>>
【问题讨论】:
-
欢迎来到 StackOverflow。但是,你的问题太笼统了。请更具体地说明您的一些“多重错误”。至少向我们展示第一条错误消息的完整回溯。如果没有,请向我们展示您的代码的输出。换句话说,阅读并关注How to create a Minimal, Complete, and Verifiable example。
-
“多个错误”。呃,这甚至没有正确缩进。我建议去opentechschool.github.io/python-beginners/en/… 了解如何使用
turtle绘制矩形。还要密切注意你的缩进,因为python的执行依赖于它。 -
turtle.fd(w)w在哪里定义?它不是。h也不是。
标签: python colors turtle-graphics