91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Python+Turtle動態繪制一棵樹實例分享

發布時間:2020-10-10 15:35:32 來源:腳本之家 閱讀:179 作者:wangsiting123 欄目:開發技術

本文實例主要是對turtle的使用,實現Python+turtle動態繪制一棵樹的實例,具體代碼:

# 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)#沿著當前的方向畫畫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 調整畫筆
 
  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. 這三條語句是一個組合相當于先把筆收起來再移動到指定位置,再把筆放下開始畫
  #否則turtle一移動就會自動的把線畫出來
 
  #t = tree([p], 200, 65, 0.6375)
  t = tree([p], 200, 65, 0.6375)
   
main()

實現效果:

Python+Turtle動態繪制一棵樹實例分享

總結

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

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

伊通| 克拉玛依市| 洛南县| 肃宁县| 虞城县| 西贡区| 扶绥县| 忻城县| 江门市| 鄂托克前旗| 松溪县| 巴里| 吉水县| 穆棱市| 喀喇沁旗| 青铜峡市| 团风县| 镇巴县| 桦南县| 平阴县| 和田市| 神木县| 富平县| 大石桥市| 定结县| 达拉特旗| 乌拉特前旗| 阳谷县| 吉安县| 大荔县| 化州市| 庐江县| 涟水县| 长武县| 石阡县| 千阳县| 洛隆县| 宁陵县| 望都县| 德保县| 呼和浩特市|