国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python+Turtle動態(tài)繪制一棵樹實(shí)例分享

2020-02-22 22:52:25
字體:
供稿:網(wǎng)友

本文實(shí)例主要是對turtle的使用,實(shí)現(xiàn)Python+turtle動態(tài)繪制一棵樹的實(shí)例,具體代碼:

# drawtree.py from turtle import Turtle, mainloop def tree(plist, l, a, f):  """ plist is list of pens  l is length of branch  a is half of the angle between 2 branches  f is factor by which branch is shortened  from level to level."""  if l > 5: #    lst = []    for p in plist:      p.forward(l)#沿著當(dāng)前的方向畫畫Move the turtle forward by the specified distance, in the direction the turtle is headed.      q = p.clone()#Create and return a clone of the turtle with same position, heading and turtle properties.      p.left(a) #Turn turtle left by angle units      q.right(a)# turn turtle right by angle units, nits are by default degrees, but can be set via the degrees() and radians() functions.      lst.append(p)#將元素增加到列表的最后      lst.append(q)    tree(lst, l*f, a, f)         def main():  p = Turtle()  p.color("green")  p.pensize(5)  #p.setundobuffer(None)  p.hideturtle() #Make the turtle invisible. It's a good idea to do this while you're in the middle of doing some complex drawing,  #because hiding the turtle speeds up the drawing observably.  #p.speed(10)  # p.getscreen().tracer(1,0)#Return the TurtleScreen object the turtle is drawing on.  p.speed(10)  #TurtleScreen methods can then be called for that object.  p.left(90)# Turn turtle left by angle units. direction 調(diào)整畫筆   p.penup() #Pull the pen up – no drawing when moving.  p.goto(0,-200)#Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle's orientation.  p.pendown()# Pull the pen down – drawing when moving. 這三條語句是一個組合相當(dāng)于先把筆收起來再移動到指定位置,再把筆放下開始畫  #否則turtle一移動就會自動的把線畫出來   #t = tree([p], 200, 65, 0.6375)  t = tree([p], 200, 65, 0.6375)   main()

實(shí)現(xiàn)效果:

總結(jié)

以上就是本文關(guān)于Python+Turtle動態(tài)繪制一棵樹實(shí)例分享的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站其他相關(guān)專題,如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 乳山市| 石屏县| 延津县| 平果县| 东平县| 无极县| 壤塘县| 且末县| 雅安市| 分宜县| 赣州市| 德保县| 河南省| 洪雅县| 万全县| 彰化县| 拉孜县| 仙桃市| 广昌县| 延长县| 聊城市| 石阡县| 丁青县| 青州市| 察哈| 屯留县| 梁河县| 汶上县| 铜川市| 北海市| 淮滨县| 进贤县| 哈巴河县| 阳东县| 博野县| 扎鲁特旗| 本溪市| 洛扎县| 平利县| 黎平县| 伊通|