-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (53 loc) · 1.78 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from tkinter import *
import random
import math
class App(Frame):
def __init__(self, master):
super().__init__(master)
self.main()
self.mainloop()
def main(self):
self.Wscreen = self.master.winfo_screenwidth()
self.Hscreen = self.master.winfo_screenheight()
self.master.title("Particules")
self.master.resizable(width=False, height=False)
self.master.bind("<Escape>", lambda e: e.widget.quit())
canvas = Canvas(self.master, width=self.Wscreen, height=self.Hscreen, bg="black")
canvas.grid()
self.setup(canvas)
def setup(self, canvas):
canvas.particles = []
self.update(canvas)
def update(self, canvas):
canvas.particles.append(
Particle(
canvas, random.randrange(self.Wscreen),
-10,
random.randrange(70, 100) / 50))
canvas.delete(ALL)
for particle in canvas.particles:
particle.draw()
if particle.y > self.Hscreen:
canvas.particles.remove(particle)
self.after(1, lambda: self.update(canvas))
class Particle():
def __init__(self, canvas, x, y, speed):
self.canvas = canvas
self.x = x
self.y = y
self.speed = speed
self.size = map(self.speed, 70/50, 100/50, 1, 7)
def draw(self):
self.particle = self.canvas.create_oval(
self.x-self.size,
self.y-self.size,
self.x+self.size,
self.y+self.size,
fill="white")
self.y = self.y + 1 * self.speed
def map(n, start1, stop1, start2, stop2):
newval = (n - start1) / (stop1 - start1) * (stop2 - start2) + start2
return newval
if __name__ == "__main__":
root = Tk()
App(root)