码迷,mamicode.com
首页 > 其他好文 > 详细

turtle练习 分形树最终优化

时间:2019-01-23 10:38:34      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:down   col   backward   size   imp   draw   back   rtl   enc   

# 绘制分形树
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练习 分形树最终优化

标签:down   col   backward   size   imp   draw   back   rtl   enc   

原文地址:https://www.cnblogs.com/kwkk978113/p/10307014.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!