turtle练习 分形树最终优化
Posted kwkk978113
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了turtle练习 分形树最终优化相关的知识,希望对你有一定的参考价值。
# 绘制分形树
import turtle
def draw_brach(brach_length):
if brach_length > 5:
turtle.pencolor("brown")
turtle.pensize(3)
turtle.forward(brach_length)
turtle.right(30)
draw_brach(brach_length - 15)
turtle.left(60)
draw_brach(brach_length - 15)
turtle.right(30)
turtle.up()
turtle.backward(brach_length)
turtle.down()
if brach_length<=10:
turtle.pencolor("green")
turtle.pensize(5)
turtle.forward(brach_length)
turtle.right(30)
draw_brach(brach_length - 15)
turtle.left(60)
draw_brach(brach_length - 15)
turtle.right(30)
turtle.up()
turtle.backward(brach_length)
turtle.down()
def main():
turtle.left(90)
turtle.up()
turtle.backward(200)
turtle.down()
turtle.pensize(10)
draw_brach(100)
turtle.exitonclick()
if __name__ == ‘__main__‘:
main()
以上是关于turtle练习 分形树最终优化的主要内容,如果未能解决你的问题,请参考以下文章