def _define_zero_symbol(self): zero = Symbol(id="zero", class_="bit-0", stroke_width=1, stroke="black", fill="none") zero.add(Circle(center=(0, 0), r=self.dimens.bit_radius, fill="none", stroke="none")) r = 0.75 n = self.poly.num_vertices for i in range(n): vertex = Point( self.dimens.bit_radius * math.sin(2 * math.pi * i / n), self.dimens.bit_radius * math.cos(2 * math.pi * i / n)) previous_vertex = Point( self.dimens.bit_radius * math.sin(2 * math.pi * (i + n - 1) / n), self.dimens.bit_radius * math.cos(2 * math.pi * (i + n - 1) / n)) start_point = Point( (1 - r) * previous_vertex.x + r * vertex.x, (1 - r) * previous_vertex.y + r * vertex.y ) next_vertex = Point( self.dimens.bit_radius * math.sin(2 * math.pi * (i + n + 1) / n), self.dimens.bit_radius * math.cos(2 * math.pi * (i + n + 1) / n)) end_point = Point( (1 - r) * next_vertex.x + r * vertex.x, (1 - r) * next_vertex.y + r * vertex.y ) line = Polyline([start_point, vertex, end_point], stroke_linejoin="bevel") zero.add(line) self.dwg.defs.add(zero)
def test_add_group(self): symbol = Symbol(id='symbol') group = symbol.add(Group(id='group')) # implicit call of add self.assertEqual(symbol.tostring(), '<symbol id="symbol"><g id="group" /></symbol>')
def test_add_subelement(self): symbol = Symbol(id='symbol') group = Group(id='group') symbol.add(group) self.assertEqual(symbol.tostring(), '<symbol id="symbol"><g id="group" /></symbol>')
def _define_one_symbol(self): dot = Symbol(id="dot") dot.add(Circle(center=(0, 0), r=self.dimens.stroke_width * 0.4, fill="black", stroke="none")) self.dwg.defs.add(dot) one = Symbol(id="one", class_="bit-1", stroke_width=1, stroke="black") one.add(Circle(center=(0, 0), r=self.dimens.bit_radius, fill="none", stroke="none")) empty_face_symbol = Symbol(id="empty_face") light_face_symbol = Symbol(id="light_face") dense_face_symbol = Symbol(id="dense_face") points = ["{} {}".format( self.dimens.bit_radius * math.sin(2 * math.pi * v / self.poly.num_vertices), self.dimens.bit_radius * math.cos(2 * math.pi * v / self.poly.num_vertices) ) for v in range(0, 3)] data = ['M', "0 0 L", *points, 'Z'] path = Path(data, fill="none", stroke_linejoin="bevel") empty_face_symbol.add(path) light_face_symbol.add(path) dense_face_symbol.add(path) x0 = 0 x1 = self.dimens.bit_radius * math.sin(2 * math.pi * 2 / self.poly.num_vertices) y0 = self.dimens.bit_radius * math.cos(2 * math.pi * 2 / self.poly.num_vertices) y1 = self.poly.outer_circle_radius * self.dimens.bit_radius w = x1 - x0 h = y1 - y0 h_rect = y1 num_dense = 200 num_light = int(num_dense / 2) points = np.apply_along_axis( lambda p: np.array([p[0] * w, p[1] * h_rect + p[0] * y0]), 1, np.clip( i4_sobol_generate(2, num_dense) + np.random.rand(num_dense, 2) / h, 0, 1 )) for p in points[:num_light]: light_face_symbol.add(Use(dot.get_iri(), (p[0], p[1]))) dense_face_symbol.add(Use(dot.get_iri(), (p[0], p[1]))) for p in points[num_light:]: dense_face_symbol.add(Use(dot.get_iri(), (p[0], p[1]))) self.dwg.defs.add(empty_face_symbol) self.dwg.defs.add(light_face_symbol) self.dwg.defs.add(dense_face_symbol) f1 = Use(empty_face_symbol.get_iri()) one.add(f1) f2 = Use(dense_face_symbol.get_iri()) f2.rotate(120) one.add(f2) f3 = Use(light_face_symbol.get_iri()) f3.rotate(240) one.add(f3) self.dwg.defs.add(one)