【发布时间】:2021-11-18 06:12:31
【问题描述】:
我正在尝试画草,我正在努力让我的画从左下角开始,然后一直到右下角。我知道我的代码有问题,但无法弄清楚。
我的代码是从中间开始的,这不是我想要的。
import turtle
import random
window = turtle.Screen()
bob = turtle.Turtle()
window.bgcolor("white")
window.title("TURTLE")
bob.pencolor("green")
window.colormode(255)
position = 0
height = 0
height11 = 0
height12 = 0
height13 = 0
height14 = 0
def draw_grass(bob):
green = random.randint (100, 200)
length = random.randint(10,20)
bob.fillcolor(0,green,0)
bob.begin_fill()
bob.setheading(90)
for i in range (2):
bob.forward(length)
bob.right(90)
bob.forward(3)
bob.right(90)
bob.end_fill()
bob.penup()
bob.pendown()
return length
for i in range (10):
height = draw_grass(bob)
position = position + 3
bob.goto(position, 0)
if height == 11 :
height11 = height11 + 1
elif height == 12:
height12 = height12 + 1
elif height == 13:
height13 = height13 + 1
【问题讨论】:
标签: python turtle-graphics python-turtle