-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMorph.py
122 lines (85 loc) · 2.67 KB
/
Morph.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from tkinter import *
import sys
WIDTH = 400 # width of canvas
HEIGHT = 400 # height of canvas
HPSIZE = 2 # half of point size (must be integer)
CCOLOR = "#0000FF" # blue
elementList = [] # list of elements (used by Canvas.delete(...))
polygon = [[50, 50], [350, 50], [350, 350], [50, 350], [50, 50]]
time = 0
dt = 0.01
def drawObjekts():
""" draw polygon and points """
# TODO: inpterpolate between polygons and render
for (p, q) in zip(polygon, polygon[1:]):
elementList.append(can.create_line(p[0], p[1], q[0], q[1],
fill=CCOLOR))
elementList.append(can.create_oval(p[0] - HPSIZE, p[1] - HPSIZE,
p[0] + HPSIZE, p[1] + HPSIZE,
fill=CCOLOR, outline=CCOLOR))
def quit(root=None):
""" quit programm """
if root == None:
sys.exit(0)
root._root().quit()
root._root().destroy()
def draw():
""" draw elements """
can.delete(*elementList)
del elementList[:]
drawObjekts()
can.update()
def forward():
global time
while (time < 1):
time += dt
polygon = getPoly(sys.argv[2],300)
print(time)
drawObjekts()
draw()
def backward():
global time
while (time > 0):
time -= dt
polygon = getPoly(sys.argv[1], 300)
print(time)
drawObjekts()
draw()
def getPoly(name,faktor=1):
temp = open(name).read().split()
temp = list(map(lambda x: float(x)*faktor, temp))
temp = list(map(lambda x: list(x),list(zip(temp[0::2],temp[1::2]))))
print(temp)
return temp
if __name__ == "__main__":
# check parameters
if len(sys.argv) != 3:
print("morph.py firstPolygon secondPolygon")
sys.exit(-1)
# TODOS:
# - read in polygons
# - transform from local into global coordinate system
# - make both polygons contain same number of points
polies = getPoly(sys.argv[1],300)
polygon = polies
# create main window
mw = Tk()
mw._root().wm_title("Morphing")
# create and position canvas and buttons
cFr = Frame(mw, width=WIDTH, height=HEIGHT, relief="sunken", bd=1)
cFr.pack(side="top")
can = Canvas(cFr, width=WIDTH, height=HEIGHT)
can.pack()
cFr = Frame(mw)
cFr.pack(side="left")
bClear = Button(cFr, text="backward", command=backward)
bClear.pack(side="left")
bClear = Button(cFr, text="forward", command=forward)
bClear.pack(side="left")
eFr = Frame(mw)
eFr.pack(side="right")
bExit = Button(eFr, text="Quit", command=(lambda root=mw: quit(root)))
bExit.pack()
draw()
# start
mw.mainloop()