-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation_maker.py
145 lines (110 loc) · 4.34 KB
/
animation_maker.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import triangle_magic
import triangle_math
import coordinates_converter
def make_combination_list(polygon_dict, other_dict):
"""takes in two dictionaries with polygon data
and returns a dictionary combining triangles
that will morph into each other"""
first_list = []
second_list = []
combination_list = []
for key in sorted(polygon_dict):
first_list.append(key)
for key in sorted(other_dict):
second_list.append(key)
if len(first_list)%2 == 1:
for i in range(len(first_list)//2 +1):
if i == 0:
key = first_list[i]
value = second_list[i]
combination_list.append((key, value))
else:
key = first_list[i]
value = second_list[i]
combination_list.append((key, value))
key = first_list[-i]
value = second_list[-i]
combination_list.append((key, value))
else:
for i in range(len(first_list)//2):
if i == 0:
key = first_list[i]
value = second_list[i]
combination_list.append((key, value))
else:
key = first_list[i]
value = second_list[i]
combination_list.append((key, value))
key = first_list[-i]
value = second_list[-i]
combination_list.append((key, value))
key = first_list[i+1]
value = second_list[i+1]
combination_list.append((key, value))
return combination_list
def wrap_css(polygon_dict, other_dict, combination_list):
wrap = ""
delay = 0
for key in sorted(polygon_dict):
polygon_id = polygon_dict[key][0]
background = polygon_dict[key][1]
polygon_coordinates = polygon_dict[key][4]
centroid_x = polygon_dict[key][3][0]
centroid_y = polygon_dict[key][3][1]
for i in range(len(combination_list)):
if combination_list[i][0] == key:
value = combination_list[i][1]
other_background = other_dict[value][1]
raw_coordinates = other_dict[value][2]
other_coordinates = triangle_magic.triang_magic(polygon_coordinates, raw_coordinates)
string = """
.object{} {{
background: {};
position: absolute;
height: 800px;
width: 800px;
animation: make_elephant{} 3s {}ms forwards;
clip-path: polygon({});
}}
@keyframes make_elephant{} {{
0% {{
background: {};
clip-path: polygon({});
}}
100% {{
background: {};
clip-path: polygon({});
}}
}}
""".format(polygon_id, background, polygon_id, delay, polygon_coordinates, polygon_id, background, polygon_coordinates, other_background, other_coordinates)
wrap += string
delay += 71
return wrap
def make_triangle_dict(factor, zero_diff):
"Generates a dictionary with all triangle date, coordinates in percent"
triangle_dict = {}
triangle_data = []
f = open('dump.txt','r')
for l in f:
line = str(l)
data_raw = line.split(" ")
polygon_id = data_raw[0]
background = data_raw[1]
# -1 to get rid of /n
polygon_coordinates = [float(data_raw[2]), float(data_raw[3]), float(data_raw[4]), float(data_raw[5]), float(data_raw[6]), float(data_raw[7])]
percent_coordinates = coordinates_converter.make_coordinates_percent(polygon_coordinates, factor, zero_diff)
print("percent_coordinates:", percent_coordinates, len(percent_coordinates))
centroid = triangle_math.make_centroid(percent_coordinates)
centroid_x = centroid[0]
css_coordinates = ""
for i in range(len(percent_coordinates)):
if i%2 == 0:
css_coordinates += str(percent_coordinates[i])[0:5] + "% "
else:
css_coordinates += str(percent_coordinates[i])[0:5] + "%, "
#....to get rid of the final comma
css_coordinates = css_coordinates[0:-2]
print ("css_coordinates:" , css_coordinates)
triangle_data = [polygon_id, background, percent_coordinates, centroid, css_coordinates]
triangle_dict[centroid_x] = triangle_data
return triangle_dict