日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

用python画树_Python+Turtle动态绘制一棵树实例分享

發布時間:2023/12/4 python 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用python画树_Python+Turtle动态绘制一棵树实例分享 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文實例主要是對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庫繪制彩虹代碼示例

Python使用Turtle模塊繪制五星紅旗代碼示例

Python內置模塊turtle繪圖詳解

Python中turtle作圖示例

使用Python的turtle模塊畫圖的方法

python 簡單的繪圖工具turtle使用詳解

時間: 2018-01-13

總結

以上是生活随笔為你收集整理的用python画树_Python+Turtle动态绘制一棵树实例分享的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。