-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathflex_scripts.py
More file actions
357 lines (295 loc) · 11.5 KB
/
Copy pathflex_scripts.py
File metadata and controls
357 lines (295 loc) · 11.5 KB
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 8 11:50:00 2020
@author: mac
These were the earliest animated GIF scripts, developed
in conjunction with:
https://github.com/4dsolutions/School_of_Tomorrow/blob/master/Flextegrity_Lattice.ipynb
"""
from flextegrity import pov_header, Cuboctahedron, Cube, Octahedron
from flextegrity import Tetrahedron, InvTetrahedron, RD, Icosahedron, Struts
from flextegrity import twelve_around_one, draw_poly, draw_vert
from qrays import Qvector
from itertools import cycle
import os
import numpy as np
import math
from itertools import permutations
g = permutations((2,1,1,0))
UNIQUE = {p for p in g} # set comprehension
IVM_DIRS = {Qvector(x) for x in UNIQUE}
PHI = (1 + math.sqrt(5))/2
Svol = (PHI **-5)/2
Evol = (math.sqrt(2)/8) * (PHI ** -3)
sfactor = Svol/Evol
def ch():
with open("concentric_hierarchy.pov", "w") as target:
target.write(pov_header)
ico = Icosahedron() * 2
cubo = Cuboctahedron() * 2
cub = Cube() * 2
rd = RD() * 2
tet = Tetrahedron() * 2
octa = Octahedron() * 2
draw_poly(ico, target)
draw_poly(cubo, target)
draw_poly(rd, target)
draw_poly(cub, target)
draw_poly(tet, target)
draw_poly(octa, target)
def iw():
with open("icosa_within.pov", "w") as target:
target.write(pov_header)
ico = 2 * Icosahedron() * 0.8
cubo = 2 * Cuboctahedron() * 0.8
octa = 2 * Octahedron() * 0.8
draw_poly(ico, target)
draw_poly(cubo, target)
draw_poly(octa, target)
def jitterbug():
with open("cubo_icosa.pov", "w") as target:
target.write(pov_header)
ico = Icosahedron()
# cubo = Cuboctahedron()
# draw_poly(cubo, target)
draw_poly(ico, target)
def logo():
with open("logo.pov", "w") as target:
target.write(pov_header)
t = Tetrahedron()
it = InvTetrahedron()
draw_poly(t, target)
draw_poly(it, target)
def cubocta_in_cube_lattice():
with open("cubocta.pov", "w") as target:
target.write(pov_header)
cubocta = Cuboctahedron()
cube = Cube()
draw_poly(cubocta, target)
for c in twelve_around_one(cube):
draw_poly(c, target)
def sphere_packing():
with open("sphere_pack2.pov", "w") as target:
target.write(pov_header)
cube = Cube()
rd = RD()
octa = Octahedron()
cubocta = Cuboctahedron()
draw_poly(cube, target)
draw_poly(octa, target)
draw_poly(rd, target)
for p in twelve_around_one(cube):
draw_poly(p, target)
for p in twelve_around_one(rd):
draw_poly(p, target)
for p in twelve_around_one(octa):
draw_poly(p, target)
cubocta.vert_radius = Qvector((2,1,1,0)).length()/2 # grow the balls
cubocta.vert_color = "rgb <1,0,0>"
draw_poly(cubocta, target, v=True, e=False)
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
def spheres_bulging():
with open("sphere_pack2.pov", "w") as target:
target.write(pov_header)
cube = Cube()
rd = RD()
octa = Octahedron()
cubocta = Cuboctahedron()
draw_poly(cube, target)
draw_poly(octa, target)
draw_poly(rd, target)
for p in twelve_around_one(cube):
draw_poly(p, target)
for p in twelve_around_one(rd):
draw_poly(p, target)
for p in twelve_around_one(octa):
draw_poly(p, target)
cubocta.vert_radius = Qvector((2,1,1,0)).length()/2 # grow the balls
cubocta.vert_color = "rgb <1,0,0>"
draw_poly(cubocta, target, v=True, e=False)
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
def animation(targdir="anim2"):
path = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
radii = np.linspace(0, 0.5, 8).tolist()
radii += reversed(radii[1:-1])
for frame_id, radius in enumerate(radii, start=1):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(path,filename), "w") as target:
target.write(pov_header)
cubocta = Cuboctahedron()
cubocta.vert_radius = radius
cubocta.vert_color = "rgb <1,0,0>"
draw_poly(cubocta, target, v=True, e=False)
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
if frame_id < 9:
rd = RD()
draw_poly(rd, target)
for p in twelve_around_one(rd):
draw_poly(p, target)
draw_poly(Cuboctahedron(), target, v=True, e=True)
def animation2(targdir="anim2"):
path = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
radii = np.linspace(0, 0.5, 8).tolist()
radii += reversed(radii[1:-1])
for frame_id, radius in enumerate(radii, start=1):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(path,filename), "w") as target:
target.write(pov_header)
cubocta = Cuboctahedron()
cubocta.vert_radius = radius
cubocta.vert_color = "rgb <1,0,0>"
draw_poly(cubocta, target, v=True, e=False)
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
if frame_id < 9:
rd = RD()
draw_poly(rd, target)
for p in twelve_around_one(rd):
draw_poly(p, target)
draw_poly(Cuboctahedron(), target, v=True, e=True)
def animation3(targdir="anim3"):
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
radii = np.linspace(0, 0.5, 8).tolist()
radii += reversed(radii[1:-1])
for frame_id, radius in enumerate(radii, start=1):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(targdir,filename), "w") as target:
target.write(pov_header)
cubocta = Cuboctahedron()
cubocta.vert_radius = radius
cubocta.vert_color = "rgb <1,0,0>"
if frame_id <= 9:
draw_poly(cubocta, target, v=True, e=False)
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
if frame_id > 9:
cube = Cube()
ico = Icosahedron() * (1/PHI * math.sqrt(2)/2) * 1.2 * radius
st = Struts(cube, ico)
draw_poly(ico, target)
draw_poly(st, target)
# draw_poly(cube, target)
for ik in twelve_around_one(ico):
draw_poly(ik, target)
# for c in twelve_around_one(cube):
# draw_poly(c, target)
for s in twelve_around_one(st):
draw_poly(s, target)
def animation4(targdir="anim4"):
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
radii = np.linspace(0.6, 1.3, 8).tolist()
radii += reversed(radii[1:-1])
for frame_id, radius in enumerate(radii, start=1):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(targdir,filename), "w") as target:
target.write(pov_header)
ico = Icosahedron() * radius
cube= Cube() * PHI * 1.5
s = Struts(cube, ico)
draw_poly(ico, target)
draw_poly(cube, target)
draw_poly(s, target)
def one_hop_away(thirteen_balls):
the_ball, *twelve_balls = thirteen_balls
newlist = [the_ball]
while True:
for idx, ball in enumerate(twelve_balls):
if (the_ball - ball).length() == 1.0:
newlist.append(ball)
the_ball = ball
break
del twelve_balls[idx]
if not twelve_balls:
break
return newlist
def animation5(targdir="anim5"):
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
thirteen_balls = [Qvector((0,0,0,0))] + list(IVM_DIRS)
neighbors = one_hop_away(thirteen_balls)
for frame_id in range(13):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(targdir,filename), "w") as target:
target.write(pov_header)
rd = RD()
draw_poly(rd, target)
for idx, p in enumerate(twelve_around_one(rd)):
if idx == frame_id:
draw_vert(neighbors[idx],
c="rgb <1,0,0>",
r=0.5, t=target)
draw_poly(p, target)
if 12 == frame_id:
draw_vert(neighbors[12],
c="rgb <1,0,0>",
r=0.5, t=target)
def animation10(targdir="anim10"):
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
thirteen_balls = [Qvector((0,0,0,0))] + list(IVM_DIRS)
neighbors = one_hop_away(thirteen_balls)
for frame_id in range(13):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(targdir,filename), "w") as target:
target.write(pov_header)
rd = RD()
draw_poly(rd, target)
for idx, p in enumerate(twelve_around_one(rd)):
if idx <= frame_id:
draw_vert(neighbors[idx],
c="rgb <1,0,0>",
r=0.5, t=target)
draw_poly(p, target)
if 12 == frame_id:
draw_vert(neighbors[12],
c="rgb <1,0,0>",
r=0.5, t=target)
def animation11(targdir="anim11"):
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
thirteen_balls = [Qvector((0,0,0,0))] + list(IVM_DIRS)
neighbors = one_hop_away(thirteen_balls)
colors = cycle(["rgb <1,0,0>", "rgb <.8,0,.2>", "rgb <.6,0,.4>",
"rgb <.4,0,.6>", "rgb <.2,0,.8>", "rgb <0,.5,.2>",
"rgb <0,.7,.2>"])
rainbow = [next(colors) for _ in range(13)]
for frame_id in range(13):
filename = f"balls{frame_id:03}.pov"
with open(os.path.join(targdir,filename), "w") as target:
target.write(pov_header)
rd = RD()
draw_poly(rd, target)
for idx, p in enumerate(twelve_around_one(rd)):
if idx <= frame_id:
draw_vert(neighbors[idx],
rainbow[idx],
r=0.4, t=target)
draw_poly(p, target)
if 12 == frame_id:
draw_vert(neighbors[12],
rainbow[12],
r=0.4, t=target)
if __name__ == "__main__":
# animation5()
# sphere_packing()
# jitterbug()
# animation()
# animation10()
# animation11()
# logo()
iw()