3
# Simulate "electrons" migrating across the screen.
4
# An optional bitmap file in can be in the background.
6
# Usage: electrons [n [bitmapfile]]
8
# n is the number of electrons to animate; default is 30.
10
# The bitmap file can be any X11 bitmap file (look in
11
# /usr/include/X11/bitmaps for samples); it is displayed as the
12
# background of the animation. Default is no bitmap.
18
# The graphical interface
22
def __init__(self, n, bitmap = None):
25
self.canvas = c = Canvas(tk)
27
width, height = tk.getint(c['width']), tk.getint(c['height'])
29
# Add background bitmap
31
self.bitmap = c.create_bitmap(width/2, height/2,
36
x1, y1, x2, y2 = 10,70,14,74
38
p = c.create_oval(x1, y1, x2, y2, fill='red')
40
y1, y2 = y1 +2, y2 + 2
43
def random_move(self, n):
46
x = random.choice(range(-2,4))
47
y = random.choice(range(-3,4))
51
# Run -- allow 500 movemens
55
self.random_move(self.n)
67
# First argument is number of electrons, default 30
69
n = string.atoi(sys.argv[1])
73
# Second argument is bitmap file, default none
76
# Reverse meaning of leading '@' compared to Tk
77
if bitmap[0] == '@': bitmap = bitmap[1:]
78
else: bitmap = '@' + bitmap
82
# Create the graphical objects...
83
h = Electrons(n, bitmap)
89
# Call main when run as script
90
if __name__ == '__main__':