inkscape-tetraflexagon-editor.svg: update the tetraflexagon example
[flexagon-toolkit.git] / src / svg_tetraflexagon_editor.py
index 0952e8a..58209c7 100755 (executable)
@@ -32,6 +32,7 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram):
         # create some layers and groups
         layers = {
             "Squares": svg.layer(label="Squares"),
         # 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")
         }
             "Tetraflexagon": svg.layer(label="Tetraflexagon"),
             "Template": svg.layer(label="Template")
         }
@@ -63,8 +64,6 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram):
                                                fill_color=(0.5, 0.5, 0.5, 0.2))
             self.backend.active_group = old_active_group
 
                                                fill_color=(0.5, 0.5, 0.5, 0.2))
             self.backend.active_group = old_active_group
 
-            self.backend.active_group = old_active_group
-
         # Draw the normal template for squares
         for square in self.tetraflexagon.squares:
             self.draw_square_template(square)
         # Draw the normal template for squares
         for square in self.tetraflexagon.squares:
             self.draw_square_template(square)
@@ -92,6 +91,19 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram):
                 ref['clip-path'] = "url(%s)" % (tile_href + '-clip-path')
                 group.add(ref)
 
                 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)
     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)
@@ -99,7 +111,7 @@ class SvgwriteTetraflexagonDiagram(TetraflexagonDiagram):
 
         super(SvgwriteTetraflexagonDiagram, self).draw_tile_template(tile, cx, cy, theta)
 
 
         super(SvgwriteTetraflexagonDiagram, self).draw_tile_template(tile, cx, cy, theta)
 
-        # The tile outline in the active group's element is the only polygon
+        # The tile outline in the active group's element is the only rectangle
         # element, so get it and set its id so that it can be reused as
         # a clip-path
         for element in self.backend.active_group.elements:
         # element, so get it and set its id so that it can be reused as
         # a clip-path
         for element in self.backend.active_group.elements: