-
Notifications
You must be signed in to change notification settings - Fork 0
/
visual.py
72 lines (51 loc) · 1.64 KB
/
visual.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
70
71
72
import Tkinter as tk
import csv
import random
import time
class App(tk.Tk):
def __init__(self):
# scale and scale1 differ for visual purposes. scale1 refers to
# the visual size of the molecules.
scale = 500/125
scale1 = 2
tk.Tk.__init__(self)
self.canvas = tk.Canvas(self, height=125 * scale, width=125 * scale,\
borderwidth=0, highlightthickness=0)
self.canvas.pack(side="top", fill="both", expand="true")
self.cellwidth= 1 * scale
self.cellheight= 1 * scale
self.oval = {}
positions = list(csv.reader(open('final_config.txt', 'rb'), delimiter='\t'))
for i in positions:
for j in xrange(3):
i[j] = float(i[j])
for i in xrange(0, 50):
x = positions[i][0]
y = positions[i][1]
self.oval[x, y] = self.canvas.create_oval(x+2*scale1\
, y+2*scale1, x-2*scale1, y-2*scale1,fill="blue",\
tags = "oval" + str(i))
self.sim()
def sim(self):
scale = 500/125
scale1 = 2
# block refers to the size of each step. Each posUpdate
# runs through all n molecules. The size of block refers
# to the number of posUpdate functions called per visual update
# delay refers to the time delay between cycles, measured
# in milliseconds
delay = 100
positions = list(csv.reader(open('final_config.txt', 'rb'), delimiter='\t'))
for i in positions:
for j in xrange(3):
i[j] = float(i[j])
for i in xrange(0, 50):
x = positions[i][0]
y = positions[i][1]
self.oval[x, y] = self.canvas.create_oval(x+2*scale1\
, y+2*scale1, x-2*scale1, y-2*scale1,fill="blue",\
tags = "oval" + str(i))
self.after(delay, lambda: self.sim())
if __name__ == '__main__':
app = App()
app.mainloop()