import tkinter as tk
from PIL import Image, ImageTk
from time import time, sleep
from random import choice, uniform, randint
from particle import Particle
# 颜色选项
colors = ['red', 'blue', 'yellow', 'white', 'green', 'orange', 'purple', 'seagreen', 'indigo', 'cornflowerblue']
HEIGHT = 800
WIDTH = 1200
def simulate(cv):
"""
循环调用保持不停
"""
t = time()
explode_points = []
wait_time = randint(10, 100)
numb_explode = randint(5, 50)
# 创建一个所有粒子同时扩大的二维列表
for point in range(numb_explode):
objects = []
x_cordi = randint(0.05 * WIDTH, 0.95 * WIDTH)
y_cordi = randint(0.05 * HEIGHT, 0.95 * HEIGHT)
speed = uniform(0.2, 2.)
size = uniform(0.2, 3)
color = choice(colors)
explosion_speed = uniform(0.1, 0.5)
explosion_radius = randint(5, 15)
total_particles = randint(20, 50)
for i in range(1, total_particles):
r = Particle(cv, idx=i, total=total_particles, explosion_speed=explosion_speed, explosion_radius=explosion_radius,
x=x_cordi, y=y_cordi, vx=speed, vy=speed, color=color, size=size, lifespan=abs(uniform(0.2, 1.75)))
objects.append(r)
explode_points.append(objects)
total_time = .0
# 1.8s内一直扩大
while total_time < 1.8:
sleep(0.01)
tnew = time()
t, dt = tnew, tnew - t
for point in explode_points:
for item in point:
item.update(dt)
cv.update()
total_time += dt
# 循环调用
root.after(wait_time, simulate, cv)
def close(*ignore):
"""退出程序、关闭窗口"""
global root
root.quit()
if __name__ == '__main__':
root = tk.Tk()
cv = tk.Canvas(root, height=HEIGHT, width=WIDTH)
# 选一个好看的背景会让效果更惊艳!
image = Image.open("./background.jpg")
photo = ImageTk.PhotoImage(image)
cv.create_image(0, 0, image=photo, anchor='nw')
cv.pack()
root.protocol("WM_DELETE_WINDOW", close)
root.after(100, simulate, cv)
root.mainloop()
程序员佳倩
- 粉丝: 895
- 资源: 5062
最新资源
- 曼哈顿矢量边界行政边界shp
- #3综合设计资料给学生.rar
- 软包电芯自动上料&焊接设备sw18全套技术资料100%好用.zip
- 砂带打磨机二坐标移动sw20可编辑全套技术资料100%好用.zip
- 烧烤烙印机sw15可编辑全套技术资料100%好用.zip
- Hadoop_2024_Fa.zip
- 开中我_开中我.开中我.apk
- 软包锂电池自动上料设备sw18可编辑全套技术资料100%好用.zip
- 湿巾纸包装袋椭圆型盖贴合设备x_t全套技术资料100%好用.zip
- 升降料仓(含DFM)sw17可编辑全套技术资料100%好用.zip
- 手持式超声波切布ug12全套技术资料100%好用.zip
- 手机标签自动贴合sw17可编辑全套技术资料100%好用.zip
- 手机电池漏液检测设备sw18全套技术资料100%好用.zip
- 手机电池上料裁切设备sw18可编辑全套技术资料100%好用.zip
- 手机键冲切机x_t全套技术资料100%好用.zip
- 手机电池压合机sw18全套技术资料100%好用.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈