用python中的递归画一棵小树

先给出画一颗小树的代码:

#tree.py
from turtle import Turtle


def tree(plist, l, a, f):
# plist is list of pens
# l is the length of brantch
# is half of the angle between 2 brantches
# f is factor by which branch is shortened from level to level
if l>5:
lst=[]
for p in plist:
p.forward(l)   #向前走l的长度
q=p.clone()
p.left(a)      #逆时针转动箭头方向
q.right(a)

lst.append(p)
lst.append(q)
tree(lst, l*f, a, f)


def main():
p=Turtle()
p.color("green")
p.pensize(5)            # set width of line(pen)
p.speed(10)             # set speed of pen (from 1 to 10)

p.hideturtle()          # 隐藏箭头

#p.getscreen().tracer(30,0)  #Return the TurtleScreen object the turtle is drawing on

p.left(90)
p.penup()
p.goto(0,0)
p.pendown()

t=tree([p],110,65,0.6375)
main()


turtle的函数调用

这里写图片描述 
这里写图片描述 
这里写图片描述


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值