为什么不是分散出去的呢?
import turtle from random import * import asyncio as a class Tree: h = 5 t = None def __init__(self, height=5): self.h = height self.t = turtle.Turtle() self.t.speed(0) self.t.seth(90) self.t.pencolor('#804000') self.t.ht() self.t.pu();self.t.goto(0, -200);self.t.pd() async def tree(self, high, t): t.pensize(high) t.fd(50) high -= 1 if not high: self.leaf(t) self.leaf(t) return elif randint(0, 1): self.leaf(t.clone()) angle = randint(10, 30) head = t.heading() ct1 = t.clone() ct2 = t.clone() ct1.seth(head + angle) ct2.seth(head - angle) await a.gather( a.create_task(self.tree(high, ct1)), a.create_task(self.tree(high, ct2)) ) #self.tree(high, ct1) #self.tree(high, ct2) def leaf(self, t): t.seth(t.heading() + randint(-90-45, 90-45)) t.pensize(1) t.color('#2F4F2F', 'green') t.begin_fill() t.circle(20, 90) t.lt(90) t.circle(20, 90) t.end_fill() def grow(self): a.run(self.tree(self.h, self.t)) #self.leaf(self.t) def main(): tree = Tree() tree.grow() turtle.mainloop() if __name__ == '__main__': main()
Sign in to make a reply
赤耳明爷
为什么不是分散出去的呢?