欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2018年01月16日 14:28:58   作者:wangsiting123  
這篇文章主要介紹了Python+Turtle動(dòng)態(tài)繪制一棵樹實(shí)例分享,具有一定借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例主要是對(duì)turtle的使用,實(shí)現(xiàn)Python+turtle動(dòng)態(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. 這三條語句是一個(gè)組合相當(dāng)于先把筆收起來再移動(dòng)到指定位置,再把筆放下開始畫
  #否則turtle一移動(dòng)就會(huì)自動(dòng)的把線畫出來
 
  #t = tree([p], 200, 65, 0.6375)
  t = tree([p], 200, 65, 0.6375)
   
main()

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

總結(jié)

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

相關(guān)文章

  • 分析PyTorch?Dataloader報(bào)錯(cuò)ValueError:num_samples的另一種可能原因

    分析PyTorch?Dataloader報(bào)錯(cuò)ValueError:num_samples的另一種可能原因

    這篇文章主要介紹了分析PyTorch?Dataloader報(bào)錯(cuò)ValueError:num_samples的另一種可能原因,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • 在Lighttpd服務(wù)器中運(yùn)行Django應(yīng)用的方法

    在Lighttpd服務(wù)器中運(yùn)行Django應(yīng)用的方法

    這篇文章主要介紹了在Lighttpd服務(wù)器中運(yùn)行Django應(yīng)用的方法,本文所采用的是最流行的FastCGI模塊,包括同時(shí)運(yùn)行多個(gè)Django應(yīng)用的方法,需要的朋友可以參考下
    2015-07-07
  • 數(shù)據(jù)清洗--DataFrame中的空值處理方法

    數(shù)據(jù)清洗--DataFrame中的空值處理方法

    今天小編就為大家分享一篇數(shù)據(jù)清洗--DataFrame中的空值處理方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2018-07-07
  • Python sqlalchemy時(shí)間戳及密碼管理實(shí)現(xiàn)代碼詳解

    Python sqlalchemy時(shí)間戳及密碼管理實(shí)現(xiàn)代碼詳解

    這篇文章主要介紹了Python sqlalchemy時(shí)間戳及密碼管理實(shí)現(xiàn)代碼詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • python三大器之裝飾器詳解

    python三大器之裝飾器詳解

    這篇文章主要介紹了Python中的裝飾器,涉及到Python中很多重要的特性,小編覺得這篇文章寫的還不錯(cuò),需要的朋友可以參考下
    2021-10-10
  • Python 中的Sympy詳細(xì)使用

    Python 中的Sympy詳細(xì)使用

    這篇文章主要介紹了Python 中的Sympy詳細(xì)使用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-08-08
  • Python 變量的創(chuàng)建過程詳解

    Python 變量的創(chuàng)建過程詳解

    這篇文章主要介紹了Python 變量的創(chuàng)建過程詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-09-09
  • python實(shí)戰(zhàn)之利用pygame實(shí)現(xiàn)貪吃蛇游戲(一)

    python實(shí)戰(zhàn)之利用pygame實(shí)現(xiàn)貪吃蛇游戲(一)

    這篇文章主要介紹了python實(shí)戰(zhàn)之利用pygame實(shí)現(xiàn)貪吃蛇游戲,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有很好的幫助喲,需要的朋友可以參考下
    2021-05-05
  • Python構(gòu)建簡單線性回歸模型

    Python構(gòu)建簡單線性回歸模型

    這篇文章主要介紹了Python構(gòu)建簡單線性回歸模型,線性回歸表示發(fā)現(xiàn)函數(shù)使用線性組合表示輸入變量。簡單線性回歸很容易理解,使用了基本的回歸技術(shù),一旦理解了這些基本概念,可以更好地學(xué)習(xí)其他類型的回歸模型
    2022-08-08
  • python實(shí)現(xiàn)文字版掃雷

    python實(shí)現(xiàn)文字版掃雷

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)文字版掃雷,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-04-04

最新評(píng)論