Beispiel #1
0
    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)