From: Antonio Ospite Date: Wed, 27 Jun 2018 18:39:36 +0000 (+0200) Subject: svg_tetraflexagon_editor: draw also the backface X-Git-Url: https://git.ao2.it/flexagon-toolkit.git/commitdiff_plain/78c5623632670822b26bac2f2790928db7becdc6?ds=sidebyside;hp=382e2be48ae8f3914bb443f27f5091c730095e6c svg_tetraflexagon_editor: draw also the backface One of the faces also have a backface, draw it to make it easier to visualize how it will look like when folding the flexagon. --- diff --git a/src/flexagon/tetraflexagon_diagram.py b/src/flexagon/tetraflexagon_diagram.py index ab3da17..a79a7a0 100755 --- a/src/flexagon/tetraflexagon_diagram.py +++ b/src/flexagon/tetraflexagon_diagram.py @@ -39,6 +39,9 @@ class TetraflexagonDiagram(object): self.plan_origin = ((self.backend.width - self.tile_side * 5) / 2, self.x_border) + self.backfaces_origin = (self.squares_centers[0][0] - self.tile_side, + self.squares_centers[0][1] + self.x_border * 2 + self.tile_side) + self.squares_color_map = [(1, 0, 0), (0, 1, 0), (0, 0, 1)] def _init_centers(self): @@ -69,6 +72,16 @@ class TetraflexagonDiagram(object): x, y = tile.calc_plan_coordinates(self.tile_side, i, j) return x0 + x, y0 + y + def get_backface_tile_transform(self, tile): + src_x, src_y = self.get_tile_center(tile) + tile_xoffset, tile_yoffset = tile.calc_offset_in_square(self.tile_side) + # When calculating dest_x the minus in the formula switches the columns. + dest_x = self.backfaces_origin[0] + self.tile_side - tile_xoffset + dest_y = self.backfaces_origin[1] + self.tile_side + tile_yoffset + + return self.backend.calc_rotate_translate_transform(src_x, src_y, + dest_x, dest_y, 0) + def get_tile_transform(self, tile): """Calculate the transformation matrix from a tile in an square to the correspondent tile in the plan. diff --git a/src/svg_tetraflexagon_editor.py b/src/svg_tetraflexagon_editor.py index 6b57160..58209c7 100755 --- a/src/svg_tetraflexagon_editor.py +++ b/src/svg_tetraflexagon_editor.py @@ -32,6 +32,7 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram): # create some layers and groups layers = { "Squares": svg.layer(label="Squares"), + "Backfaces": svg.layer(label="Backfaces"), "Tetraflexagon": svg.layer(label="Tetraflexagon"), "Template": svg.layer(label="Template") } @@ -90,6 +91,19 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram): ref['clip-path'] = "url(%s)" % (tile_href + '-clip-path') group.add(ref) + # A tri-tetraflexagon only have one visible backface, the first one. + group = self.groups["Backfaces"] + for tile in self.tetraflexagon.squares[0].tiles: + m = self.get_backface_tile_transform(tile) + svg_matrix = "matrix(%f, %f, %f, %f, %f, %f)" % (m[0], m[3], + m[1], m[4], + m[2], m[5]) + tile_href = "#square0-tile%d" % tile.index + ref = self.backend.svg.use("#square0-content") + ref['transform'] = svg_matrix + ref['clip-path'] = "url(%s)" % (tile_href + '-clip-path') + group.add(ref) + def draw_tile_template(self, tile, cx, cy, theta): old_active_group = self.backend.active_group group_name = "square%d-tile%d" % (tile.square.index, tile.index)