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

歡迎訪問 生活随笔!

生活随笔

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

python

python知识:用turtle绘制樱桃树

發布時間:2025/3/21 python 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python知识:用turtle绘制樱桃树 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

用pyhon的turtle結合分形知識,進行櫻花樹的繪畫,供大家研究。

代碼來源在github上,Turtle/cherry tree.py at main · AXYZdong/Turtle · GitHub,大家自己下載,或拷貝粘貼下述代碼。

1 代碼實現

import turtle as T import random import time# 畫櫻花的軀干(60,t) def Tree(branch, t):time.sleep(0.0005)if branch > 3:if 8 <= branch <= 12:if random.randint(0, 2) == 0:t.color('snow') # 白else:t.color('lightcoral') # 淡珊瑚色t.pensize(branch / 3)elif branch < 8:if random.randint(0, 1) == 0:t.color('snow')else:t.color('lightcoral') # 淡珊瑚色t.pensize(branch / 2)else:t.color('sienna') # 赭(zhě)色t.pensize(branch / 10) # 6t.forward(branch)a = 1.5 * random.random()t.right(20 * a)b = 1.5 * random.random()Tree(branch - 10 * b, t)t.left(40 * a)Tree(branch - 10 * b, t)t.right(20 * a)t.up()t.backward(branch)t.down()# 掉落的花瓣 def Petal(m, t):for i in range(m):a = 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 fallingFlowers(m):x, y = -900, -400for i in range(30):t.up()t.goto(x, y)x += 100t.down()yval = 50for i in range(m):a = 100 * random.random()b = 2 * random.random()if a > 59:t.color('#FE2E9A')else:t.color('#04B486')t.circle(5)t.up()t.goto(x, y + (yval * b))t.fd(a)yval += 50t.down()# 愛心def Love(x, y):t.up()t.home()t.goto(x, y)t.pensize(4)t.color('pink', 'pink') # 粉t.left(90)t.forward(100)t.down()t.begin_fill()t.circle(70, 230)t.forward(140)t.end_fill()t.begin_fill()t.seth(40)t.forward(135)t.right(5)t.circle(70, 235)t.end_fill()t.up()# 文字 def Font():t.penup()t.goto(-500, -300)t.pencolor('black')t.write("By AXYZdong,不一樣的櫻花+愛心送給不一樣的你,520", font=('方正行黑簡體', 30, 'normal'))# 繪圖區域 t = T.Turtle() # 畫布大小 w = T.Screen() t.hideturtle() # 隱藏畫筆 t.getscreen().tracer(5, 0) w.screensize(1000, 800, 'wheat') # wheat小麥 t.left(90) t.up() t.backward(150) t.down() t.color('sienna')# 畫櫻花的軀干 Tree(60, t) # 掉落的花瓣 Petal(300, t)fallingFlowers(10) # 愛心 Love(-400, 100) Love(400, 100) Love(-400, -150) Love(400, -150) # 文字 Font() w.exitonclick()

2 參考結果

總結

以上是生活随笔為你收集整理的python知识:用turtle绘制樱桃树的全部內容,希望文章能夠幫你解決所遇到的問題。

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