<强>废话不多说了,直接上代码吧! 强>
# !/usr/bin/env python #=utf - 8编码 #画一棵樱花 进口甲鱼 进口随机 从海龟进口* 从进口睡眠时间 #画樱花的躯干(60 t) def树(branchLen t): 睡眠(0.0005) 如果branchLen祝辞3: 如果8 & lt;=branchLen & lt;=12: 如果random.randint (0, 2)==0: t.color #白(“雪”) 其他: t.color (lightcoral) #淡珊瑚色 t。pensize (branchLen/3) elif branchLen & lt; 8: 如果random.randint (0,1)==0: t.color(雪) 其他: t.color (lightcoral) #淡珊瑚色 t。pensize (branchLen/2) 其他: t.color(黄土)#赭(zhě)色 t。pensize (branchLen/10) # 6 t.forward (branchLen)=1.5 * random.random () t.right (20 *) b=1.5 * random.random () 树(branchLen-10 * b、t) t.left (40 *) 树(branchLen-10 * b、t) t.right (20 *) t.up () t.backward (branchLen) t.down () #掉落的花瓣 def花瓣(m t): 我的范围(米): 一个=200 - 400 * random.random () b=10 - 20 * random.random () t.up () t.forward (b) t.left (90) t.forward (a) t.down () t.color (lightcoral) #淡珊瑚色 t.circle (1) t.up () t.backward (a) t.right (90) t.backward (b) def main (): #绘图区域 t=turtle.Turtle () #画布大小 w=turtle.Screen () t.hideturtle() #隐藏画笔 getscreen () .tracer (5,0) w.screensize (bg=靶÷蟆?#小麦小麦 t.left (90) t.up () t.backward (150) t.down () t.color(黄土) #画樱花的躯干 树(60 t) #掉落的花瓣 花瓣(200 t) w.exitonclick () main () >之前
以上这篇python3实现用龟模块画一棵随机樱花树就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。
python3实现用龟模块画一棵随机樱花的树