<jupyter_start><jupyter_text>Chair Tiling<jupyter_code>########################################
# Set up the finite subdivision rules
########################################

# The chair tiling only has one prototile
rules = TilingRules()
chair = rules.createPrototile("chair", [("A", PointE2(0,0)),
                                        ("B", PointE2(1,0)),
                                        ("C", PointE2(2,0)),
                                        ("D", PointE2(2,1)),
                                        ("E", PointE2(1,1)),
                                        ("F", PointE2(1,2)),
                                        ("G", PointE2(0,2)),
                                        ("H", PointE2(0,1))])

def chair_newverts(vDict):
    a = vDict["a"].point
    h = vDict["h"].point
    A = vDict["A"].point
    
    e0 = a - A
    e1 = h - A
    
    vDict["i"].point = A + 3 * e0 + e1
    vDict["j"].point = A + 2 * e0 + e1
    vDict["k"].point = A + e0 + e1
    vDict["l"].point = A + e0 + 2 * e1
    vDict["m"].point = A + e0 + 3 * e1

# Edges that need to be split
chair.addSplitEdgeRules(((("A","B"), ("a"), midp), 
                         (("B","C"), ("b"), midp), 
                         (("C","D"), ("c"), midp),
                         (("D","E"), ("d"), midp), 
                         (("E","F"), ("e"), midp), 
                         (("F","G"), ("f"), midp),
                         (("G","H"), ("g"), midp), 
                         (("H","A"), ("h"), midp)))

# New vertices to create
chair.addNewVertexRules(("i","j","k","l","m"))
chair.setNewVertexHandlerFn(chair_newverts)

# The subdivision subtiles: 
chair.addSubtile("chair", ("A", "a", "B", "j", "k", "l", "H", "h"))
chair.addSubtile("chair", ("G", "g", "H", "l", "m", "e", "F", "f"))
chair.addSubtile("chair", ("k", "j", "i", "d", "E", "e", "m", "l"))
chair.addSubtile("chair", ("C", "c", "D", "d", "i", "j", "B", "b"))

########################################
# Apply the rules
########################################

tiling = rules.generateTiling("chair", depth = 4)
GeometricTilingViewer(tiling, 
                      size=(800, 800), 
                      shadedLevel=3, #colors in super tiles at a particular level
                      style_fn=tileIdx_fill_fromList(["red", "green", "blue", "orange", "violet", "#30a"])
                     ).show()
packing, _ = generateCirclePackingLayout(tiling)
CirclePackedTilingViewer(
    tiling, 
    packing, 
    shadedLevel = 3
).show()
tutteGraph = tutteEmbeddingE2(tiling, 
                              in_place = False, 
                              verbose = False)
TutteEmbeddedTilingViewer(tiling, tutteGraph, shadedLevel = 3).show()<jupyter_output><empty_output><jupyter_text>Twisted pentagonal tiling<jupyter_code>from koebe.algorithms.tiling import *
from koebe.algorithms.tutteEmbeddings import tutteEmbeddingE2

########################################
# Set up the finite subdivision rules
########################################

# The chair tiling only has one prototile
pent_rules = TilingRules()

pent = pent_rules.createPrototile("pent", tuple("ABCDE"))

# Edges that need to be split
pent.addSplitEdgeRules(((("A","B"), ("a", "b")), 
                        (("B","C"), ("c", "d")), 
                        (("C","D"), ("e", "f")),
                        (("D","E"), ("g", "h")), 
                        (("E","A"), ("i", "j"))))

# New vertices to create
pent.addNewVertexRules(("k"))

# The subdivision subtiles: 
pent.addSubtile("pent", tuple("Aabkj"))
pent.addSubtile("pent", tuple("Bcdkb"))
pent.addSubtile("pent", tuple("Cefkd"))
pent.addSubtile("pent", tuple("Dghkf"))
pent.addSubtile("pent", tuple("Eijkh"))

########################################
# Apply the rules
########################################

pent_tiling = pent_rules.generateTiling("pent", depth = 4)
pent_packing, _ = generateCirclePackingLayout(pent_tiling)
CirclePackedTilingViewer(
    pent_tiling, 
    pent_packing,
    showTriangulation = True
).show()
tutteGraph = tutteEmbeddingE2(pent_tiling, 
                              in_place = False, 
                              verbose = False)
TutteEmbeddedTilingViewer(pent_tiling, tutteGraph, shadedLevel = 2).show()<jupyter_output><empty_output><jupyter_text>Twisted Hexagonal Tiling<jupyter_code>########################################
# Set up the finite subdivision rules
########################################

# The chair tiling only has one prototile
hex_rules = TilingRules()

hex = hex_rules.createPrototile("hex", ["A_A", "B", "C", "D", "E", "F"])

# Edges that need to be split
hex.addSplitEdgeRules(( 
                        (("A_A","B"), ("a1", "a2", "a3")), 
                        (("B","C"), ("b1", "b2", "b3")), 
                        (("C","D"), ("c1", "c2", "c3")),
                        (("D","E"), ("d1", "d2", "d3")), 
                        (("E","F"), ("e1", "e2", "e3")),
                        (("F","A_A"), ("f1", "f2", "f3"))
                      ))

# New vertices to create
hex.addNewVertexRules(("x"))

# The subdivision subtiles: 
hex.addSubtile("hex", ("A_A", "a1", "a2", "a3", "x", "f3"))
hex.addSubtile("hex", ("B", "b1", "b2", "b3", "x", "a3"))
hex.addSubtile("hex", ("C", "c1", "c2", "c3", "x", "b3"))
hex.addSubtile("hex", ("D", "d1", "d2", "d3", "x", "c3"))
hex.addSubtile("hex", ("E", "e1", "e2", "e3", "x", "d3"))
hex.addSubtile("hex", ("F", "f1", "f2", "f3", "x", "e3"))

########################################
# Apply the rules
########################################

hex_tiling = hex_rules.generateTiling("hex", depth = 5)

tutteGraph = tutteEmbeddingE2(hex_tiling, 
                              in_place = False, 
                              verbose = False)
TutteEmbeddedTilingViewer(hex_tiling, tutteGraph, shadedLevel = 3).show()<jupyter_output><empty_output><jupyter_text>Twisted n-agonal tiling<jupyter_code>########################################
# Set up the finite subdivision rules
########################################

# The chair tiling only has one prototile
N = 9
ntile_rules = TilingRules()

ntile = ntile_rules.createPrototile("ntile", [f"V{i}" for i in range(N)])

# Edges that need to be split
ntile.addSplitEdgeRules([((f"V{i}",f"V{(i+1)%N}"), [f"v{i}_{j}" for j in range(1, N-2)])
                        for i in range(N)])

# New vertices to create
ntile.addNewVertexRules(("x"))

# The subdivision subtiles: 
for i in range(N):
    ntile.addSubtile("ntile", [f"V{i}"] + [f"v{i}_{j}" for j in range(1, N-2)] + ["x", f"v{(i+N-1)%N}_{N-3}"])

########################################
# Apply the rules
########################################

ntile_tiling = ntile_rules.generateTiling("ntile", depth = 4)

tutteGraph = tutteEmbeddingE2(ntile_tiling, 
                              in_place = False, 
                              verbose = False)
TutteEmbeddedTilingViewer(ntile_tiling, tutteGraph, shadedLevel = 2).show()<jupyter_output><empty_output><jupyter_text>Two-Prototile Experimental<jupyter_code>########################################
# Set up the finite subdivision rules
########################################

# The chair tiling only has one prototile
rules = TilingRules()

t0 = rules.createPrototile("t0", tuple("AB"))
t1 = rules.createPrototile("t1", tuple("ABC"))
t2 = rules.createPrototile("t2", tuple("ABCDEF"))
t3 = rules.createPrototile("t3", tuple("ABCD"))

# Edges that need to be split
t1.addSplitEdgeRules((
    (("A", "B"), ("a1", "a2")),
    (("B", "C"), ("b")),
    (("C", "A"), ("c"))
))
t2.addSplitEdgeRules((
    (("A", "B"), ("a1", "a2")),
    (("B", "C"), ("b1", "b2")),
    (("C", "D"), ("c1", "c2")),
    (("D", "E"), ["d1"]),
    (("E", "F"), ("e1", "e2")),
    (("F", "A"), ["f1"]),
))
t3.addSplitEdgeRules((
    (("A", "B"), ["a1", "a2"]), 
    (("B", "C"), ["b1"]), 
    (("C", "D"), ["c1", "c2"]), 
    (("D", "A"), ["d1"])
))

# New vertices to create
t0.addNewVertexRules(("x"))
t2.addNewVertexRules(("x", "y"))
t3.addNewVertexRules(("x", "y"))

# The subdivision subtiles: 
t0.addSubtile("t1", ("A", "B", "x"))
t0.addSubtile("t1", ("B", "A", "x"))
#t0.addSubtile("t1", ("C", "A", "x"))

t1.addSubtile("t1", ("c", "b", "C"))
t1.addSubtile("t2", ("A", "a1", "a2", "B", "b", "c"))

t2.addSubtile("t3", ("f1", "x", "e2", "F"))
t2.addSubtile("t3", ("x", "y", "e1", "e2"))
t2.addSubtile("t3", ("y", "d1", "E", "e1"))
t2.addSubtile("t2", ("A", "a1", "a2", "B", "x", "f1"))
t2.addSubtile("t2", ("B", "b1", "b2", "C", "y", "x"))
t2.addSubtile("t2", ("C", "c1", "c2", "D", "d1", "y"))

t3.addSubtile("t3", ("A", "a1", "x", "d1"))
t3.addSubtile("t3", ("a1", "a2", "y", "x"))
t3.addSubtile("t3", ("a2", "B", "b1", "y"))
t3.addSubtile("t3", ("y", "b1", "C", "c1"))
t3.addSubtile("t3", ("x", "y", "c1", "c2"))
t3.addSubtile("t3", ("d1", "x", "c2", "D"))


########################################
# Apply the rules
########################################

tiling = rules.generateTiling("t0", depth = 7)
tutteGraph = tutteEmbeddingE2(tiling, 
                              in_place = False, 
                              verbose = True)
TutteEmbeddedTilingViewer(tiling, tutteGraph, shadedLevel = 3).show()<jupyter_output>Duplicating DCEL...
done.
Reordering vertices...
done.
Laying out boundary...
done.
Computing graph laplacian...
Creating vertToIdx array...
Creating vertToDeg array...
Creating mat...
Done.
Returning coo_matrix with shape (20121, 20121)
done.
Computing Tutte embedding...
Computing P1...
Computing L1...
Computing B...
Computing L2...
Computing -inv(L2)
Computing nInvL2*B*P1
Concatenating P1 and P2
done.
Setting .data attributes...
done.<jupyter_text>Dodecahedral Tiling<jupyter_code>from koebe.algorithms.tiling import *
rules = TilingRules()

tri  = rules.createPrototile("tri", tuple("ABC"))
quad = rules.createPrototile("quad", tuple("ABCD"))
pent = rules.createPrototile("pent", tuple("ABCDE"))

# Subdivision of the tri
tri.addSplitEdgeRules((
    (("A", "B"), ("AB0", "AB1", "AB2", "AB3")),
    (("B", "C"), ("BC0", "BC1", "BC2", "BC3")),
    (("C", "A"), ("CA0", "CA1", "CA2", "CA3"))
))

tri.addNewVertexRules(("a", "b", "c", "d", "e", "f", 
                       "g", "h", "i", "j", "k", "l", 
                       "m", "n", "o", "p", "q", "r", 
                       "s", "t", "u", "v", "w", "x",
                       "y", "z", "a0", "a1", "a2", "a3"))

tri.addSubtile("pent", ("A", "AB0", "a", "q", "CA3"))
tri.addSubtile("quad", ("AB1", "b", "a", "AB0"))
tri.addSubtile("pent", ("AB1", "AB2", "d", "c", "b"))
tri.addSubtile("quad", ("AB3", "e", "d", "AB2"))
tri.addSubtile("pent", ("AB3", "B", "BC0", "f", "e"))
tri.addSubtile("quad", ("BC1", "g", "f", "BC0"))
tri.addSubtile("pent", ("BC1", "BC2", "y", "z", "g"))
tri.addSubtile("quad", ("BC3", "a0", "y", "BC2"))
tri.addSubtile("tri", ("k", "z", "a3"))
tri.addSubtile("quad", ("g", "z", "k", "h"))
tri.addSubtile("tri", ("f", "g", "h"))
tri.addSubtile("pent", ("C", "CA0", "a1", "a0", "BC3"))
tri.addSubtile("quad", ("CA1", "v", "a1", "CA0"))
tri.addSubtile("pent", ("CA1", "CA2", "r", "s", "v"))
tri.addSubtile("quad", ("CA3", "q", "r", "CA2"))
tri.addSubtile("quad", ("o", "p", "q", "a"))
tri.addSubtile("tri", ("a", "b", "o"))
tri.addSubtile("quad", ("n", "o", "b", "c"))
tri.addSubtile("tri", ("n", "c", "i"))
tri.addSubtile("quad", ("c", "d", "a2", "i"))
tri.addSubtile("tri", ("d", "e", "a2"))
tri.addSubtile("quad", ("e", "f", "h", "a2"))
tri.addSubtile("quad", ("z", "y", "x", "a3"))
tri.addSubtile("tri", ("y", "a0", "x"))
tri.addSubtile("quad", ("a0", "a1", "w", "x"))
tri.addSubtile("tri", ("w", "a1", "v"))
tri.addSubtile("quad", ("v", "s", "u", "w"))
tri.addSubtile("tri", ("s", "t", "u"))
tri.addSubtile("quad", ("p", "t", "s", "r"))
tri.addSubtile("tri", ("q", "p", "r"))
tri.addSubtile("pent", ("o", "n", "m", "t", "p"))
tri.addSubtile("pent", ("a2", "h", "k", "j", "i"))
tri.addSubtile("pent", ("l", "a3", "x", "w", "u"))
tri.addSubtile("quad", ("t", "m", "l", "u"))
tri.addSubtile("quad", ("i", "j", "m", "n"))
tri.addSubtile("quad", ("a3", "l", "j", "k"))
tri.addSubtile("tri", ("m", "j", "l"))

# Subdivision of the quad

quad.addSplitEdgeRules((
    (("A", "B"), ("AB0", "AB1")),
    (("B", "C"), ("BC0", "BC1", "BC2", "BC3")),
    (("C", "D"), ("CD0", "CD1")),
    (("D", "A"), ("DA0", "DA1", "DA2", "DA3"))
))

quad.addNewVertexRules(("a", "b", "c", "d", "e", "f", 
                       "g", "h", "i", "j", "k", "l", 
                       "m", "n", "o", "p", "q", "r", 
                       "s", "t", "u", "v", "w", "x"))

quad.addSubtile("pent", ("A", "AB0", "a", "n", "DA3"))
quad.addSubtile("pent", ("B", "BC0", "c", "b", "AB1"))
quad.addSubtile("pent", ("BC1", "BC2", "f", "e", "d"))
quad.addSubtile("pent", ("C", "CD0", "h", "g", "BC3"))
quad.addSubtile("pent", ("D", "DA0", "j", "i", "CD1"))
quad.addSubtile("pent", ("DA1", "DA2", "m", "l", "k"))
quad.addSubtile("pent", ("o", "p", "q", "w", "x"))
quad.addSubtile("pent", ("t", "u", "v", "r", "s"))

quad.addSubtile("tri", ("a", "b", "o"))
quad.addSubtile("tri", ("c", "d", "p"))
quad.addSubtile("tri", ("e", "r", "q"))
quad.addSubtile("tri", ("f", "g", "s"))
quad.addSubtile("tri", ("h", "i", "t"))
quad.addSubtile("tri", ("j", "k", "u"))
quad.addSubtile("tri", ("v", "l", "w"))
quad.addSubtile("tri", ("x", "m", "n"))

quad.addSubtile("quad", ("a", "AB0", "AB1", "b"))
quad.addSubtile("quad", ("c", "BC0", "BC1", "d"))
quad.addSubtile("quad", ("f", "BC2", "BC3", "g"))
quad.addSubtile("quad", ("h", "CD0", "CD1", "i"))
quad.addSubtile("quad", ("j", "DA0", "DA1", "k"))
quad.addSubtile("quad", ("m", "DA2", "DA3", "n"))
quad.addSubtile("quad", ("o", "x", "n", "a"))
quad.addSubtile("quad", ("p", "o", "b", "c"))
quad.addSubtile("quad", ("q", "p", "d", "e"))
quad.addSubtile("quad", ("e", "f", "s", "r"))
quad.addSubtile("quad", ("g", "h", "t", "s"))
quad.addSubtile("quad", ("i", "j", "u", "t"))
quad.addSubtile("quad", ("k", "l", "v", "u"))
quad.addSubtile("quad", ("x", "w", "l", "m"))
quad.addSubtile("quad", ("w", "q", "r", "v"))

# Subdivision of the pent
pent.addSplitEdgeRules((
    (("A", "B"), ("AB0", "AB1")),
    (("B", "C"), ("BC0", "BC1")),
    (("C", "D"), ("CD0", "CD1")),
    (("D", "E"), ("DE0", "DE1")),
    (("E", "A"), ("EA0", "EA1"))
))

pent.addNewVertexRules(("a", "b", "c", "d", "e", "f", 
                       "g", "i", "j", "k", "l",  # I accidentally skipped h in my drawing, oh well...
                       "m", "n", "o", "p"))

pent.addSubtile("pent", ("A", "AB0", "a", "k", "EA1"))
pent.addSubtile("pent", ("B", "BC0", "c", "b", "AB1"))
pent.addSubtile("pent", ("C", "CD0", "e", "d", "BC1"))
pent.addSubtile("pent", ("D", "DE0", "g", "f", "CD1"))
pent.addSubtile("pent", ("E", "EA0", "j", "i", "DE1"))
pent.addSubtile("pent", ("l", "m", "n", "o", "p"))

pent.addSubtile("quad", ("a", "AB0", "AB1", "b"))
pent.addSubtile("quad", ("c", "BC0", "BC1", "d"))
pent.addSubtile("quad", ("e", "CD0", "CD1", "f"))
pent.addSubtile("quad", ("g", "DE0", "DE1", "i"))
pent.addSubtile("quad", ("j", "EA0", "EA1", "k"))
pent.addSubtile("quad", ("l", "p", "k", "a"))
pent.addSubtile("quad", ("m", "l", "b", "c"))
pent.addSubtile("quad", ("n", "m", "d", "e"))
pent.addSubtile("quad", ("o", "n", "f", "g"))
pent.addSubtile("quad", ("p", "o", "i", "j"))

pent.addSubtile("tri", ("a", "b", "l"))
pent.addSubtile("tri", ("c", "d", "m"))
pent.addSubtile("tri", ("e", "f", "n"))
pent.addSubtile("tri", ("g", "i", "o"))
pent.addSubtile("tri", ("j", "k", "p"))


dodecahedral_tiling = rules.generateTiling("pent", depth = 3)
from koebe.algorithms.tutteEmbeddings import tutteEmbeddingE2

tutteGraph = tutteEmbeddingE2(dodecahedral_tiling, 
                              in_place = False, 
                              verbose = False)

TutteEmbeddedTilingViewer(
    dodecahedral_tiling, 
    tutteGraph, 
    edgeStyle=makeStyle(stroke="#113", strokeWeight=1.0),
    shadedLevel = 2,
    style_fn = tileType_fill_fromDict({"pent":"#2a3e83",
                                       "quad":"#feeb54",
                                       "tri":"#a3945d"})
).show()
tileType_fill_fromDict({"pent":"red","quad":"blue","tri":"purple"})
print(len(dodecahedral_tiling.verts))
print(len(dodecahedral_tiling.edges))
print(len(dodecahedral_tiling.faces)-1)
dodecahedral_packing, _ = generateCirclePackingLayout(dodecahedral_tiling)
CirclePackedTilingViewer(
    dodecahedral_tiling, 
    dodecahedral_packing,
    showTriangulation = True
).show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.3112655449890271, 'fraction_numerical': 0.022616435015849794, 'mean_word_length': 3.5798436627582357, 'pattern_counts': {'":': 6, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '533211', 'license': 'MIT', 'n_tokens_mistral': 6540, 'n_tokens_neox': 6335, 'n_words': 1388, 'path': 'Example Notebooks/Tiling Examples.ipynb', 'repo_name': 'johncbowers/koebepy', 'size': '16404'}