theta1, theta2 = math.pi * 2 / p1, math.pi * 2 / p2 phiSum = math.pi * 2 / q r1 = triangleSideForAngles(theta1 / 2, phiSum / 2, theta2 / 2) r2 = triangleSideForAngles(theta2 / 2, phiSum / 2, theta1 / 2) tGen1 = htiles.TileGen.makeRegular(p1, hr=r1, skip=1) tGen2 = htiles.TileGen.makeRegular(p2, hr=r2, skip=1) decorator1 = TileDecoratorFish(p1, p2, q) tLayout = TileLayoutFish() tLayout.addGenerator(tGen1, ((0, 1) * 10)[:p1], decorator1) tLayout.addGenerator(tGen2, ((0, 1, 2) * 10)[:p2], htiles.TileDecoratorNull()) startTile = tLayout.startTile(code=0, rotateDeg=rotate) tiles = tLayout.tilePlane(startTile, depth=depth) d = Drawing(2, 2, origin='center') d.draw(euclid.shapes.Circle(0, 0, 1), fill='silver') for tile in tiles: d.draw(tile, layer=0) for tile in tiles: d.draw(tile, layer=1) for tile in tiles: d.draw(tile, layer=2) d.setRenderSize(w=400) d.saveSvg('Tess02.svg') #Rest of code I already commented in Tess01
class Tiling: def __init__(self, vertex_1: Vertex, vertex_2: Vertex, vertex_3: Vertex): self._vertices = {} self._edges = {} self._tiles = {} self._edges_to_tiles = {} self._tiles_to_colours = {} self._vertices_to_colours = {} self._boundary = [vertex_1, vertex_2, vertex_3] self._colour_values = ["#eeeeee", "#111111", "#bb9977", "#99bb77"] self._drawing = Drawing(2, 2, origin='center') self._drawing.setRenderSize(4096) self._populate_data() def _populate_data(self): for index, vertex in enumerate(self._boundary): self._vertices[vertex] = vertex edge = Edge(*tuple(set(self._boundary) - {vertex})) self._edges[edge] = edge self._vertices_to_colours[vertex] = index + 1 tile = Tile(*self._boundary) self._tiles[tile] = tile self._tiles_to_colours[tile] = 0 for edge in self._edges: self._edges_to_tiles[edge] = {tile} self._drawing.draw( tile, fill=self._colour_values[self._tiles_to_colours[tile]]) def _build_new_tile(self, vertex_1: Vertex, vertex_2: Vertex) -> Vertex: edge = self._edges[Edge(vertex_1, vertex_2)] #assert len(self._edges_to_tiles[edge]) == 1 inner_tile = tuple(self._edges_to_tiles[edge])[0] inner_vertex = tuple(inner_tile.vertices - {vertex_1, vertex_2})[0] reflected_vertex = Line.from_points(vertex_1, vertex_2).reflection(inner_vertex) reflected_vertex = self._add_vertex(reflected_vertex) self._add_edge(Edge(vertex_1, reflected_vertex)) self._add_edge(Edge(vertex_2, reflected_vertex)) new_tile = self._add_tile(Tile(vertex_1, reflected_vertex, vertex_2)) self._vertices_to_colours[ reflected_vertex] = self._vertices_to_colours[inner_vertex] self._tiles_to_colours[new_tile] = self._vertices_to_colours[ inner_vertex] ^ self._tiles_to_colours[inner_tile] self._drawing.draw( new_tile, fill=self._colour_values[self._tiles_to_colours[new_tile]]) return reflected_vertex def _add_vertex(self, vertex: Vertex) -> Vertex: if vertex not in self._vertices: self._vertices[vertex] = vertex return self._vertices[vertex] def _add_edge(self, edge: Edge): if edge not in self._edges: self._edges[edge] = edge self._edges_to_tiles[edge] = set() def _add_tile(self, tile: Tile): if tile not in self._tiles: self._tiles[tile] = tile tile = self._tiles[tile] edge_1 = self._edges[Edge(tile.vertex_2, tile.vertex_3)] edge_2 = self._edges[Edge(tile.vertex_3, tile.vertex_1)] edge_3 = self._edges[Edge(tile.vertex_1, tile.vertex_2)] self._edges_to_tiles[edge_1].add(tile) self._edges_to_tiles[edge_2].add(tile) self._edges_to_tiles[edge_3].add(tile) return tile def _draw(self, depth: int): with open('images/logo-depth-{}-data.json'.format(depth), 'w') as f: json.dump([path.args for path in self._drawing.elements], f, indent=2) self._drawing.saveSvg('images/logo-depth-{}.svg'.format(depth)) def create_tiles(self, depth: int): if depth == 0: self._draw(depth) return self.create_tiles(depth=depth - 1) print(f"Populating depth {depth}...") new_boundary = [ self._build_new_tile(self._boundary[0], self._boundary[-1]) ] index = 0 counter = 0 num_tiles = (3 * sqrt(3) * ((2 + sqrt(3))**depth - (2 - sqrt(3))**depth)).as_int() while True: new_vertex = self._build_new_tile(new_boundary[-1], self._boundary[index]) counter += 1 print(f"created {counter} / {num_tiles} tiles...", end="\r") if new_vertex in self._boundary: index += 1 elif new_vertex in new_boundary: break else: new_boundary.append(new_vertex) self._boundary = new_boundary self._draw(depth) print(f"Populated, found {len(self._tiles)} tiles")
edges = [] for i, point in enumerate(points): v1 = vertices[i] v2 = vertices[(i + 1) % p1] edge = Hypercycle.fromPoints(*v1, *v2, *point, segment=True, excludeMid=True) edges.append(edge) decoratePoly = Polygon(edges=edges, vertices=vertices) decorator1 = htiles.TileDecoratorPolygons(decoratePoly) tLayout.setDecorator(decorator1, 0) startTile = tLayout.defaultStartTile(rotateDeg=rotate) tiles = tLayout.tilePlane(startTile, depth=6) d = Drawing(2, 2, origin='center') #d.draw(euclid.shapes.Circle(0, 0, 1), fill='silver') for tile in tiles: d.draw(tile, hwidth=0.05, fill='green') tiles[0].decorator = None d.draw(Hypercycle.fromPoints(*tiles[0].vertices[0], *tiles[0].vertices[1], *pointBase), hwidth=0.05, fill='black') d.setRenderSize(w=300) d.saveSvg('Tess03.svg') d