代码拉取完成,页面将自动刷新
同步操作将从 metabolism/FlowerQrCode 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from turtle import *
from random import *
from math import *
import requests
import time
leaf_num = 0
scan_num = 0
class Tree:
def __init__(self):
setup(.99, .99)
bgcolor(1, 1, 1) # 背景色
bgpic("background_1300_700.png")
# ht() # 隐藏turtle
speed(0) # 速度 1-10渐进,0 最快
# tracer(1, 100) # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延
tracer(1, 0)
pu() # 抬笔
backward(100) # 100
# 保证笔触箭头方向始终不向下,此处使其左转90度,而不是右转
left(90) # 左转90度
backward(300) # 后退300
def tree(self, n, l):
scan_num_url = "http://www.mossesblog.com/get/scanNum"
pd() # 下笔
# 阴影效果
t = cos(radians(heading() + 45)) / 8 + 0.25
pencolor(t, t, t)
pensize(n / 1.0)
forward(l) # 画树枝
global leaf_num
if leaf_num < 10:
while int(requests.get(scan_num_url).json()['infoNum']) <= leaf_num:
time.sleep(2)
if n > 0:
b = random() * 15 + 15 # 右分支偏转角度
c = random() * 15 + 15 # 左分支偏转角度
d = l * (random() * 0.25 + 0.7) # 下一个分支的长度
# 右转一定角度,画右分支
right(b)
self.tree(n - 1, d)
# 左转一定角度,画左分支
left(b + c)
self.tree(n - 1, d)
# 转回来
right(c)
else:
# 画叶子
right(90)
# n = cos(radians(heading() - 45)) / 4 + 0.5
n = cos(radians(heading() - 45)) / 4 + 0.5
# pencolor(n, n * 0.8, n * 0.8)
pencolor("green")
fillcolor("green")
# fillcolor(n, n * 0.8, n * 0.8)
begin_fill()
circle(3)
left(90)
end_fill()
leaf_num = leaf_num+1
# if leaf_num > 100:
if leaf_num < 200 and random() > 0.75:
pu()
# 飘落
t = heading()
an = -40 + random() * 40
setheading(an)
dis = int(800 * random() * 0.5 + 400 * random() * 0.3 + 200 * random() * 0.2)
forward(dis)
setheading(t)
# 画叶子
pd()
right(90)
n = cos(radians(heading() - 45)) / 4 + 0.5
# pencolor(n * 0.5 + 0.5, 0.4 + n * 0.4, 0.4 + n * 0.4)
pencolor("green")
fillcolor("green")
# fillcolor(n, n * 0.8, n * 0.8)
begin_fill()
circle(2)
left(90)
end_fill()
pu()
# 返回
t = heading()
setheading(an)
backward(dis)
setheading(t)
# # 添加0.3倍的飘落叶子
# if random() > 0.7:
# pass
pu()
backward(l) # 退回
def scan_num_increase():
global scan_num
scan_num = scan_num+1
print("scan_num:", scan_num)
def main():
start = time.time()
tree = Tree()
tree.tree(10, 95) # 递归7层
# url = "http://www.mossesblog.com/get/scanNum"
# r = requests.get(url)
# print(r)
# print(r.json()['infoNum'])
end = time.time()
print("共耗时...",end-start)
done()
if __name__ == '__main__':
main()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。