def generate_path_tree(self): """ Specialized path generation for your origami pattern """ # retrieve conversion factor for selected unit unit_factor = self.calc_unit_factor() # retrieve saved parameters, and apply unit factor where needed width = self.options.width * unit_factor height = self.options.height * unit_factor if self.options.width_delta_bool: width_delta = self.options.width_delta * unit_factor width += width_delta height -= width_delta / 2 length = math.sqrt(2) * (width + 2 * height) half_fold = 90 if self.options.simulation_mode else 180 # bottom of box ring_inner = Path.generate_square(width, width, center=[0, 0], style='m', fold_angle=half_fold) # ring making the corners lengths = [height, width, height] points = Path.get_square_points(sum(lengths), sum(lengths), [0, 0]) styles = ['vmv', 'mmm'] ring_middle = [ Path([points[i], points[(i + 1) % 4]], 'm').break_path(lengths, styles[i % 2]) for i in range(4) ] # arms along width and length points = [(-width / 2, -(width / 2 + 0 * height)), (-width / 2, -(width / 2 + 1 * height)), (-width / 2, -(width / 2 + 2 * height)), (+width / 2, -(width / 2 + 2 * height)), (+width / 2, -(width / 2 + 1 * height)), (+width / 2, -(width / 2 + 0 * height))] arms_ = [ Path.list_create_from_points( points, 'mmvmm', fold_angles=[180, 180, half_fold, 180, 180]), Path.list_create_from_points(points, 'mvvvm', half_fold) ] arms = [Path.list_rotate(arms_[i % 2], i * pi / 2) for i in range(4)] # tiny corner diagonals diag = Path([(width / 2, width / 2), (width / 2 + height, width / 2 + height)], 'v') corner_diagonals = [diag * (1, i * pi / 2) for i in range(4)] self.edge_points = Path.get_square_points(length, length) self.path_tree = [ring_inner, ring_middle, arms, corner_diagonals] self.path_tree = recenter(self.path_tree, length / 2)
def generate_path_tree(self): """ Specialized path generation for your origami pattern """ # retrieve conversion factor for selected unit unit_factor = self.calc_unit_factor() # retrieve saved parameters, and apply unit factor where needed length = self.options.length * unit_factor vertex_radius = self.options.vertex_radius * unit_factor pattern = self.options.pattern angle = self.options.angle * pi / 180 fold_angle_valley = self.options.fold_angle_valley # create all Path instances defining strokes # first define its points as a list of tuples... left_right_stroke_points = [(length / 2, 0), (length / 2, length)] up_down_stroke_points = [(0, length / 2), (length, length / 2)] # doing the same for diagonals diagonal_1_stroke_points = [(0, 0), (length, length)] diagonal_2_stroke_points = [(0, length), (length, 0)] # ... and then create the Path instances, defining its type ('m' for mountain, etc...) if pattern == 'template1': up_down = [ Path(left_right_stroke_points, 'm', fold_angle=180.), Path(up_down_stroke_points, 'm', fold_angle=180.) ] diagonals = [ Path(diagonal_1_stroke_points, 'v', fold_angle=fold_angle_valley), Path(diagonal_2_stroke_points, 'v', fold_angle=fold_angle_valley) ] else: up_down = [ Path(left_right_stroke_points, 'v', fold_angle=fold_angle_valley), Path(up_down_stroke_points, 'v', fold_angle=fold_angle_valley) ] diagonals = [ Path(diagonal_1_stroke_points, 'm', fold_angle=180.), Path(diagonal_2_stroke_points, 'm', fold_angle=180.) ] vertices = [] for i in range(3): for j in range(3): vertices.append( Path(((i / 2.) * length, (j / 2.) * length), style='p', radius=vertex_radius)) # multiplication is implemented as a rotation, and list_rotate implements rotation for list of Path instances vertices = Path.list_rotate(vertices, angle, (1 * length, 1 * length)) up_down = Path.list_rotate(up_down, angle, (1 * length, 1 * length)) diagonals = Path.list_rotate(diagonals, angle, (1 * length, 1 * length)) # if Path constructor is called with more than two points, a single stroke connecting all of then will be # created. Using method generate_separated_paths, you can instead return a list of separated strokes # linking each two points # create a list for edge strokes # create path from points to be able to use the already built rotate method edges = Path.generate_square(length, length, 'e', rotation=angle) edges = Path.list_rotate(edges, angle, (1 * length, 1 * length)) # IMPORTANT: the attribute "path_tree" must be created at the end, saving all strokes self.path_tree = [up_down, diagonals, vertices] # IMPORTANT: at the end, save edge points as "self.edge_points", to simplify selection of single or multiple # strokes for the edge self.edge_points = edges.points