【发布时间】:2021-12-30 20:16:54
【问题描述】:
我有一个绘制砖墙的功能,可以选择在绘制墙之前设置某种笔颜色,但是无论我做什么,砖似乎都被绘制为绿色:
def draw_brick(length, width):
t.color("green")
t.begin_fill()
for i in range(2):
t.forward(length)
t.right(90)
t.forward(width)
t.right(90)
t.end_fill()
def draw_row(row_type, bricks):
if row_type == "A":
for i in range(bricks):
draw_brick(50, 30)
t.penup()
t.forward(70)
t.pendown()
elif row_type == "B":
draw_brick(12, 30)
t.penup()
t.forward(35)
t.pendown()
for i in range(bricks - 1):
draw_brick(50, 30)
t.penup()
t.forward(70)
t.pendown()
t.penup()
t.pendown()
draw_brick(12, 30)
def draw_brick_wall(rows, brick, top_row, new_color):
t.pencolor(new_color)
if top_row == "A":
drawing_A = True
else:
drawing_A = False
for i in range(rows):
next_position = (t.xcor(), t.ycor() - 40)
if drawing_A:
draw_row("A", brick)
else:
draw_row("B", brick)
drawing_A = not (drawing_A)
move_no_trails(next_position[0], next_position[1])
# resets turtle to postion (x, y)
def move_no_trails(x, y):
t.penup()
t.goto(x, y)
t.pendown()
但是,由于某种原因,乌龟的笔颜色没有改变。我能做些什么来解决这个问题?
【问题讨论】:
-
里面有很多缺失的代码。这些函数之外的一些事情可能会影响结果(例如,对全局
tvariable 的操作,draw_row中的代码)
标签: python turtle-graphics python-turtle