from itertools import permutations
g = permutations((2,1,1,0))
UNIQUE = {p for p in g} # set comprehension
print(UNIQUE)
{(0, 1, 1, 2), (1, 0, 1, 2), (2, 0, 1, 1), (0, 2, 1, 1), (0, 1, 2, 1), (1, 2, 1, 0), (1, 1, 2, 0), (2, 1, 1, 0), (1, 0, 2, 1), (1, 2, 0, 1), (2, 1, 0, 1), (1, 1, 0, 2)}
import os
os.chdir('/Users/mac/Documents/School_of_Tomorrow')
os.getcwd()
'/Users/mac/Documents/School_of_Tomorrow'
from qrays import Qvector
IVM_DIRS = {Qvector(x) for x in UNIQUE}
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
IVM
{0: {ivm_vector(a=0, b=0, c=0, d=0)}}
import flextegrity
import flex_scripts
import imp
imp.reload(flextegrity)
imp.reload(flex_scripts)
<module 'flex_scripts' from '/Users/mac/Documents/School_of_Tomorrow/flex_scripts.py'>
from flextegrity import Edge, pov_header, Cuboctahedron, Icosahedron, Struts, Cube, RD
from flextegrity import twelve_around_one, draw_edge, draw_poly, draw_vert
import flextegrity
def add_layer():
global IVM
directions = [Qvector(u) for u in UNIQUE]
maxlayer = max(IVM.keys())
nextlayer = maxlayer + 1
the_set = set()
for idx, center in enumerate(IVM[maxlayer]):
# print(idx)
for v in directions:
candidate = center + v
# print("Checking", candidate)
if (candidate in IVM[maxlayer]):
# print(candidate, "no good")
continue
if (maxlayer-1 in IVM) and (candidate in IVM[maxlayer-1]):
# print(candidate, "no good")
continue
# print(candidate, "OK!")
the_set.add(candidate)
IVM[nextlayer] = the_set
add_layer()
len(IVM[5])
252
edges = set()
def check_in(v0, v1):
candidate = tuple(sorted([v0, v1]))
edges.add(candidate)
def get_edges():
for layer in IVM:
for ball in IVM[layer]:
for v in IVM_DIRS:
other = ball + v
if other in IVM[layer]:
check_in(ball, other)
continue
if layer-1 in IVM:
if other in IVM[layer - 1]:
# check_in(ball, other)
continue
if layer+1 in IVM:
if other in IVM[layer+1]:
# check_in(ball, other)
continue
def make_edge_list():
the_list = []
for e in edges:
the_list.append(Edge(*e))
return the_list
IVM
{0: {ivm_vector(a=0, b=0, c=0, d=0)}, 1: {ivm_vector(a=0, b=1, c=1, d=2), ivm_vector(a=0, b=1, c=2, d=1), ivm_vector(a=0, b=2, c=1, d=1), ivm_vector(a=1, b=0, c=1, d=2), ivm_vector(a=1, b=0, c=2, d=1), ivm_vector(a=1, b=1, c=0, d=2), ivm_vector(a=1, b=1, c=2, d=0), ivm_vector(a=1, b=2, c=0, d=1), ivm_vector(a=1, b=2, c=1, d=0), ivm_vector(a=2, b=0, c=1, d=1), ivm_vector(a=2, b=1, c=0, d=1), ivm_vector(a=2, b=1, c=1, d=0)}}
with open("ivm_test.pov", "w") as target:
c = "rgb <0, 0, 1>"
target.write(pov_header)
for e in make_edge_list():
draw_edge(e, c, 0.03, target)
edges = set()
get_edges()
len(edges)
1320
IVM.keys()
dict_keys([0, 1])
import math
PHI = (1 + math.sqrt(5))/2.0
flextegrity.IVM = IVM
with open("flextegrity5.pov", "w") as target:
target.write(pov_header)
c = Cube()
ico = Icosahedron() * (1/PHI * math.sqrt(2)/2)
st = Struts(c, ico, suppress=True)
draw_poly(ico, target)
draw_poly(st, target)
for ik in twelve_around_one(ico):
draw_poly(ik, target)
for s in twelve_around_one(st):
draw_poly(s, target, v = False)
IVM
{0: {ivm_vector(a=0, b=0, c=0, d=0)}, 1: {ivm_vector(a=0, b=1, c=1, d=2), ivm_vector(a=0, b=1, c=2, d=1), ivm_vector(a=0, b=2, c=1, d=1), ivm_vector(a=1, b=0, c=1, d=2), ivm_vector(a=1, b=0, c=2, d=1), ivm_vector(a=1, b=1, c=0, d=2), ivm_vector(a=1, b=1, c=2, d=0), ivm_vector(a=1, b=2, c=0, d=1), ivm_vector(a=1, b=2, c=1, d=0), ivm_vector(a=2, b=0, c=1, d=1), ivm_vector(a=2, b=1, c=0, d=1), ivm_vector(a=2, b=1, c=1, d=0)}}
def all_ivm(p):
translations = [ ]
maxlayer = max(IVM.keys())
for layer in range(maxlayer, 0, -1):
for t in IVM[layer]:
translations.append(p + t)
return translations
def flextegrity6():
global IVM
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
add_layer()
add_layer()
flextegrity.IVM = IVM
with open("flextegrity6.pov", "w") as target:
target.write(pov_header)
c = Cube()
ico = Icosahedron() * (1/PHI * math.sqrt(2)/2) * 0.7
st = Struts(c, ico, suppress=True)
draw_poly(ico, target)
draw_poly(st, target)
for ik in all_ivm(ico):
draw_poly(ik, target)
for s in all_ivm(st):
draw_poly(s, target, v = False)
flextegrity6()
def outer_ivm(p):
translations = [ ]
maxlayer = max(IVM.keys())
for t in IVM[maxlayer]:
translations.append(p + t)
return translations
def flextegrity7():
global IVM
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
add_layer()
add_layer()
add_layer()
del IVM[2]
del IVM[1]
del IVM[0]
flextegrity.IVM = IVM
with open("flextegrity7.pov", "w") as target:
target.write(pov_header)
c = Cube()
cubo = Cuboctahedron() * 3
ico = Icosahedron() * (1/PHI * math.sqrt(2)/2)
st = Struts(c, ico, suppress=True)
draw_poly(cubo, target)
#draw_poly(st, target)
for ik in outer_ivm(ico):
draw_poly(ik, target)
for s in outer_ivm(st):
draw_poly(s, target, v = False)
flextegrity7()
print(pov_header)
// Persistence of Vision Ray Tracer Scene Description File // File: xyz.pov // Vers: 3.6 // Desc: test file // Date: Sat Sep 7 09:49:33 2019 // Auth: me // ==== Standard POV-Ray Includes ==== #include "colors.inc" // Standard Color definitions // include "textures.inc" // Standard Texture definitions // include "functions.inc" // internal functions usable in user defined functions // ==== Additional Includes ==== // Don't have all of the following included at once, it'll cost memory and time // to parse! // --- general include files --- // include "chars.inc" // A complete library of character objects, by Ken Maeno // include "skies.inc" // Ready defined sky spheres // include "stars.inc" // Some star fields // include "strings.inc" // macros for generating and manipulating text strings // --- textures --- // include "finish.inc" // Some basic finishes // include "glass.inc" // Glass textures/interiors // include "golds.inc" // Gold textures // include "metals.inc" // Metallic pigments, finishes, and textures // include "stones.inc" // Binding include-file for STONES1 and STONES2 // include "stones1.inc" // Great stone-textures created by Mike Miller // include "stones2.inc" // More, done by Dan Farmer and Paul Novak // include "woodmaps.inc" // Basic wooden colormaps // include "woods.inc" // Great wooden textures created by Dan Farmer and Paul Novak global_settings {assumed_gamma 1.0} global_settings {ambient_light rgb<1, 1, 1> } // perspective (default) camera camera { location <6, 0.1, 0.2> rotate <45, 45, 10.0> look_at <0.0, 0.0, 0.0> right x*image_width/image_height } // create a regular point light source light_source { 0*x // light's position (translated below) color rgb <1,1,1> // light's color translate <-20, 15, 10> } // create a regular point light source light_source { 0*x // light's position (translated below) color rgb <1,1,1> // light's color translate <20, -15, -10> } background { color rgb <1.0, 1.0, 1.0> }
with open("pov_header_snapshot_rotation.pov", "w") as f:
f.write(pov_header)
# pov_header = pov_header.replace("look_at <0.0, 0.0, 0.0>", "look_at <0.0, -1.0, 0.0>")
pov_header = pov_header.replace("rotate <45, 45, 10.0>", "// rotate <0, -2, 10.0>")
# pov_header = pov_header.replace("rotate <45, 45, 10.0>", "rotate <0, -2, 10.0>")
# pov_header = pov_header.replace("location <8, 0.1, 0.2>", "location <10, 0.1, 0.2>")
def flextegrity_film(r, frame):
with open(frame, "w") as target:
target.write(pov_header)
c = Cube()
ico = Icosahedron() * (1/PHI * math.sqrt(2)/2) * r
st = Struts(c, ico, suppress=True)
draw_poly(ico, target)
draw_poly(st, target)
for ik in all_ivm(ico):
draw_poly(ik, target)
for s in all_ivm(st):
draw_poly(s, target, v = False)
import numpy as np
global IVM
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
add_layer()
add_layer()
flextegrity.IVM = IVM
def animation6(targdir="anim6"):
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 = os.path.join(targdir,f"balls{frame_id:03}.pov")
flextegrity_film(radius, filename)
animation6()
from flextegrity import U,X,V
def add_tet_layer():
global IVM
directions = [U,X,V]
maxlayer = max(IVM.keys())
nextlayer = maxlayer + 1
the_set = set()
for idx, center in enumerate(IVM[maxlayer]):
# print(idx)
for v in directions:
candidate = center + v
# print("Checking", candidate)
if (candidate in IVM[maxlayer]):
# print(candidate, "no good")
continue
if (maxlayer-1 in IVM) and (candidate in IVM[maxlayer-1]):
# print(candidate, "no good")
continue
# print(candidate, "OK!")
the_set.add(candidate)
IVM[nextlayer] = the_set
import numpy as np
edges = set()
global IVM
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
add_tet_layer()
add_tet_layer()
add_tet_layer()
add_tet_layer()
flextegrity.IVM = IVM
cubocta = Cuboctahedron()
cubocta.vert_radius = 0.03
cubocta.vert_color = "rgb <1,0,0>"
targdir="anim8"
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
for frame_id, angle in enumerate(range(0,360,2), start=1):
filename = os.path.join(targdir,f"balls{frame_id:03}.pov")
if not f"rotate <0, {angle-2}, 10.0>" in pov_header:
print("Not found!")
break
else:
pov_header = pov_header.replace(f"rotate <0, {angle-2}, 10.0>", f"rotate <0, {angle}, 10.0>")
assert f"rotate <0, {angle}, 10.0>" in pov_header
with open(filename, "w") as target:
target.write(pov_header)
for ball in all_ivm( Qvector((0,0,0,0)) ):
draw_vert(ball, c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
get_edges()
for e in make_edge_list():
draw_edge(e, c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
Not found!
with open("pov_header_snapshot_rotation.pov", "r") as f:
pov_header = f.read()
edges = set()
global IVM
IVM = {}
IVM[0] = {Qvector((0,0,0,0))}
add_tet_layer()
add_tet_layer()
add_tet_layer()
add_tet_layer()
flextegrity.IVM = IVM
cubocta = Cuboctahedron()
cubocta.vert_radius = 0.03
cubocta.vert_color = "rgb <1,0,0>"
targdir="anim9"
targdir = os.path.join(".",targdir)
if not os.path.isdir(targdir):
os.mkdir(targdir)
for frame_id, angle in enumerate(range(0,360,2), start=1):
filename = os.path.join(targdir,f"balls{frame_id:03}.pov")
if not f"rotate <0, {angle-2}, 10.0>" in pov_header:
print("Not found!")
break
else:
pov_header = pov_header.replace(f"rotate <0, {angle-2}, 10.0>", f"rotate <0, {angle}, 10.0>")
assert f"rotate <0, {angle}, 10.0>" in pov_header
with open(filename, "w") as target:
target.write(pov_header)
if 1 <= frame_id <= 90:
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=0.5*frame_id/90, t=target)
for ball in all_ivm( Qvector((0,0,0,0)) ):
draw_vert(ball, c=cubocta.vert_color,
r=0.5*frame_id/135, t=target)
if 90 < frame_id <= 180:
draw_vert(Qvector((0,0,0,0)), c=cubocta.vert_color,
r=0.5*(180-frame_id)/90, t=target)
for ball in all_ivm( Qvector((0,0,0,0)) ):
draw_vert(ball, c=cubocta.vert_color,
r=0.5*(180-frame_id)/90, t=target)
if (0 <= frame_id < 65) or (125 <= frame_id <= 180):
get_edges()
for e in make_edge_list():
draw_edge(e, c=cubocta.vert_color,
r=cubocta.vert_radius, t=target)
rd = RD()
draw_poly(rd, target)
for p in all_ivm(rd):
draw_poly(p, target)
Not found!
2 <= 3
True
import flex_scripts
flex_scripts.animation5()
import os
os.chdir('/Users/mac/Documents/School_of_Tomorrow/anim11')
files = sorted([fname for fname in os.listdir(".") if ".pov" in fname])
for f in files:
cmd = "/usr/local/bin/povray +A +H768 +W1024 ./{}".format(f)
print("Processing...", cmd)
output = os.system(cmd)
Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls000.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls001.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls002.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls003.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls004.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls005.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls006.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls007.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls008.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls009.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls010.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls011.pov Processing... /usr/local/bin/povray +A +H768 +W1024 ./balls012.pov