我正在尝试使用 L 系统生成一棵简单的树。但是,当我运行我拥有的代码时:
import turtle
def generate(length):
sentence = "F"
for j in range(1, length):
for i in sentence:
if i == "F":
sentence += "FF+[+F-F-F]-[-F+F+F]"
print(sentence)
gen = turtle.Turtle()
window = turtle.Screen()
gen.left(90)
for k in sentence:
if k == "F":
gen.forward(10)
elif k == "+":
gen.right(10)
elif k == "-":
gen.left(10)
elif k == "[":
location = gen.position()
elif k == "]":
gen.setposition(location)
我在海龟窗口中得到一个奇怪的纹理图案:
我怎样才能产生想要的结果?