def generate_kresling_zigzag(sides, radius, angle_ratio, add_attachment): theta = (pi / 2.) * (1 - 2. / sides) l = 2. * radius * cos(theta * (1. - angle_ratio)) a = 2. * radius * sin(pi / sides) # b = sqrt(a * a + l * l - 2 * a * l * cos(angle_ratio * theta)) # phi = abs(acos((l * l + b * b - a * a) / (2 * l * b))) # gamma = pi / 2 - angle_ratio * theta - phi dy = l * sin(theta * angle_ratio) dx = l * cos(theta * angle_ratio) - a points = [] styles = [] for i in range(sides): points.append((i * a, 0)) points.append(((i + 1) * a + dx, -dy)) styles.append('v') if i != sides - 1: styles.append('m') elif add_attachment: points.append((sides * a, 0)) styles.append('m') path = Path.generate_separated_paths(points, styles) return path
def effect(self): """ Main function, called when the extension is run. """ # construct dictionary containing styles self.create_styles_dict() # get paths for selected origami pattern self.generate_path_tree() # ~ accuracy = self.options.accuracy # ~ unit_factor = self.calc_unit_factor() # what page are we on # page_id = self.options.active_tab # sometimes wrong the very first time # Translate according to translate attribute g_attribs = { inkex.addNS('label', 'inkscape'): '{} Origami pattern'.format(self.options.pattern), # inkex.addNS('transform-center-x','inkscape'): str(-bbox_center[0]), # inkex.addNS('transform-center-y','inkscape'): str(-bbox_center[1]), inkex.addNS('transform-center-x', 'inkscape'): str(0), inkex.addNS('transform-center-y', 'inkscape'): str(0), 'transform': 'translate(%s,%s)' % self.translate } # add the group to the document's current layer if type(self.path_tree) == list and len(self.path_tree) != 1: self.topgroup = etree.SubElement(self.get_layer(), 'g', g_attribs) else: self.topgroup = self.get_layer() if len(self.edge_points) == 0: Path.draw_paths_recursively(self.path_tree, self.topgroup, self.styles_dict) elif self.options.edge_single_path: edges = Path(self.edge_points, 'e', closed=True) Path.draw_paths_recursively(self.path_tree + [edges], self.topgroup, self.styles_dict) else: edges = Path.generate_separated_paths(self.edge_points, 'e', closed=True) Path.draw_paths_recursively(self.path_tree + edges, self.topgroup, self.styles_dict)
def generate_kresling_zigzag(sides, cols, radius, angle_ratio): # def generate_kresling_zigzag(sides, radius, angle_ratio, add_attachment): theta = (pi / 2.) * (1 - 2. / sides) l = 2. * radius * cos(theta * (1. - angle_ratio)) a = 2. * radius * sin(pi / sides) dy = l * sin(theta * angle_ratio) dx = l * cos(theta * angle_ratio) - a points = [] styles = [] for i in range(cols): points.append((i * a, 0)) points.append(((i + 1) * a + dx, dy)) styles.append('v') if i != cols - 1: styles.append('m') # elif add_attachment: # points.append((sides * a, 0)) # styles.append('m') path = Path.generate_separated_paths(points, styles) return path
def effect(self): """ Main function, called when the extension is run. """ # bypass most style options if simulation mode is choosen self.check_simulation_mode() # check if any selected to print only some of the crease types: bool_only_list = [ self.options.mountain_bool_only, self.options.valley_bool_only, self.options.edge_bool_only, self.options.universal_bool_only, self.options.semicrease_bool_only, self.options.cut_bool_only, self.options.vertex_bool_only ] if sum(bool_only_list) > 0: self.options.mountain_bool = self.options.mountain_bool and self.options.mountain_bool_only self.options.valley_bool = self.options.valley_bool and self.options.valley_bool_only self.options.edge_bool = self.options.edge_bool and self.options.edge_bool_only self.options.universal_bool = self.options.universal_bool and self.options.universal_bool_only self.options.semicrease_bool = self.options.semicrease_bool and self.options.semicrease_bool_only self.options.cut_bool = self.options.cut_bool and self.options.cut_bool_only self.options.vertex_bool = self.options.vertex_bool and self.options.vertex_bool_only # construct dictionary containing styles self.create_styles_dict() # get paths for selected origami pattern self.generate_path_tree() # ~ accuracy = self.options.accuracy # ~ unit_factor = self.calc_unit_factor() # what page are we on # page_id = self.options.active_tab # sometimes wrong the very first time # get vertex points and add them to path tree vertex_radius = self.options.vertex_radius * self.calc_unit_factor() vertices = [] self.vertex_points = list(set([i for i in self.vertex_points ])) # remove duplicates for vertex_point in self.vertex_points: vertices.append(Path(vertex_point, style='p', radius=vertex_radius)) self.path_tree.append(vertices) # Translate according to translate attribute g_attribs = { inkex.addNS('label', 'inkscape'): '{} Origami pattern'.format(self.options.pattern), # inkex.addNS('transform-center-x','inkscape'): str(-bbox_center[0]), # inkex.addNS('transform-center-y','inkscape'): str(-bbox_center[1]), inkex.addNS('transform-center-x', 'inkscape'): str(0), inkex.addNS('transform-center-y', 'inkscape'): str(0), 'transform': 'translate(%s,%s)' % self.translate } # add the group to the document's current layer if type(self.path_tree) == list and len(self.path_tree) != 1: self.topgroup = inkex.etree.SubElement(self.get_layer(), 'g', g_attribs) else: self.topgroup = self.get_layer() if len(self.edge_points) == 0: Path.draw_paths_recursively(self.path_tree, self.topgroup, self.styles_dict) elif self.options.edge_single_path: edges = Path(self.edge_points, 'e', closed=True) Path.draw_paths_recursively(self.path_tree + [edges], self.topgroup, self.styles_dict) else: edges = Path.generate_separated_paths(self.edge_points, 'e', closed=True) Path.draw_paths_recursively(self.path_tree + edges, self.topgroup, self.styles_dict)