#!/usr/bin/env python3""" turtle-example-suite:tdemo_tree.pyDisplays a 'breadth-first-tree' - in contrastto the classical Logo tree drawing programs,which use a depth-first-algorithm.Uses:(1) a tree-generator, where the drawing isquasi the side-effect, whereas the generatoralways yields None.(2) Turtle-cloning: At each branching pointthe current pen is cloned. So in the endthere are 1024 turtles."""from turtle import Turtle, mainloopfrom time import perf_counter as clockdef tree(plist, l, a, f):""" plist is list of pensl is length of brancha is half of the angle between 2 branchesf is factor by which branch is shortenedfrom level to level."""if l > 3:lst = []for p in plist:p.forward(l)q = p.clone()p.left(a)q.right(a)lst.append(p)lst.append(q)for x in tree(lst, l*f, a, f):yield Nonedef maketree():p = Turtle()p.setundobuffer(None)p.hideturtle()p.speed(0)p.getscreen().tracer(30,0)p.left(90)p.penup()p.forward(-210)p.pendown()t = tree([p], 200, 65, 0.6375)for x in t:passdef main():a=clock()maketree()b=clock()return "done: %.2f sec." % (b-a)if __name__ == "__main__":msg = main()print(msg)mainloop()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。