1
# Brownian motion -- an example of a NON multi-threaded Tkinter program ;)
2
# By Michele Simoniato, inspired by brownian.py
16
stop = 0 # Set when main loop exits
17
root = None # main window
19
def particle(canvas): # particle = iterator over the moves
21
x = random.gauss(WIDTH/2.0, SIGMA)
22
y = random.gauss(HEIGHT/2.0, SIGMA)
23
p = canvas.create_oval(x-r, y-r, x+r, y+r, fill=FILL)
25
dx = random.gauss(0, BUZZ)
26
dy = random.gauss(0, BUZZ)
28
canvas.move(p, dx, dy)
34
def move(particle): # move the particle at random time
36
dt = random.expovariate(LAMBDA)
37
root.after(int(dt*1000), move, particle)
42
canvas = Canvas(root, width=WIDTH, height=HEIGHT)
43
canvas.pack(fill='both', expand=1)
47
for i in range(np): # start the dance
48
move(particle(canvas))
54
if __name__ == '__main__':