当前仓库属于关闭状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 2

self / FlowerQrCode
关闭

forked from metabolism / FlowerQrCode
关闭
 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
flower.py 3.69 KB
一键复制 编辑 原始数据 按行查看 历史
metabolism 提交于 2019-10-06 21:02 . 二维码
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(10) # 速度 1-10渐进,0 最快
# tracer(1, 100) # 设置绘图屏幕刷新频率,参数1设置在正常刷新频次的第参数1次刷新,参数2设置每次刷新的时延
tracer(1, 0.1)
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
print("画笔阴影效果是", t)
pencolor(t, t, t)
pensize(n / 1.0)
print("penSize是", n/1.0)
forward(l) # 画树枝
global leaf_num
r = requests.get(scan_num_url)
print(r.json())
print(leaf_num)
if leaf_num < 150:
while int(requests.get(scan_num_url).json()['infoNum']) <= leaf_num:
time.sleep(2)
if n > 0:
b = random() * 15 + 20 # 右分支偏转角度
c = random() * 15 + 20 # 左分支偏转角度
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)) / 3 + 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.5)
left(90)
end_fill()
leaf_num = leaf_num+1
# if leaf_num > 100:
if random() > 0.7:
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(8, 90) # 递归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()
Python
1
https://gitee.com/self49/FlowerQrCode.git
git@gitee.com:self49/FlowerQrCode.git
self49
FlowerQrCode
FlowerQrCode
master

搜索帮助