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):
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.
# 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")
}
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)