Exemple #1
0
    def render(
            self,
            output,
            image_size,
            show_vertices_labels=False,
            draw_alternative_domains=True,
            draw_polygon_edges=True,
            draw_inner_lines=False,
            draw_labelled_edges=False,
            vertex_size=0.1,
            line_width=0.07,
            checker=False,
            checker_colors=("#1E7344", "#EAF78D"),
            face_colors=("lightcoral", "mistyrose", "steelblue"),
    ):
        trans = Transform.merge(Transform.diskToHalf(),
                                Transform.translation((-0.00001, 0)))
        d = drawSvg.Drawing(12, 6, origin=(-6, 0))
        d.append(drawSvg.Rectangle(-10, -10, 20, 20, fill="silver"))

        bar = tqdm.tqdm(desc="processing polygons", total=self.num_faces)

        # draw the faces
        for (i, j), flist in self.face_indices.items():
            if checker:
                style1 = {"fill": checker_colors[0]}
                style2 = {"fill": checker_colors[1]}
            else:
                vertex_index = self.vertex_at_mirrors(i, j)
                color = face_colors[vertex_index]
                style1 = {"fill": color}
                style2 = {"fill": color, "opacity": 0.3}

            for k, face in enumerate(flist):
                # coords of the vertices of this face
                points = [self.project(p) for p in face.coords]
                polygon = Polygon.fromVertices(points)
                # compute the alternate domains
                domain1, domain2 = face.get_alternative_domains()
                domain1_2d = [[self.project(p) for p in D] for D in domain1]
                domain2_2d = [[self.project(p) for p in D] for D in domain2]

                # draw domains of even reflections
                for D in domain1_2d:
                    poly = Polygon.fromVertices(D)
                    d.draw(poly, transform=trans, **style1)
                    if checker:
                        d.draw(poly, transform=trans, hwidth=0.005, **style1)
                    if draw_inner_lines:
                        d.draw(poly,
                               transform=trans,
                               fill="papayawhip",
                               hwidth=0.015)
                # draw domains of odd reflections
                for D in domain2_2d:
                    poly = Polygon.fromVertices(D)
                    d.draw(poly, transform=trans, **style2)
                    if checker:
                        d.draw(poly, transform=trans, hwidth=0.005, **style2)
                    if draw_inner_lines:
                        d.draw(poly,
                               transform=trans,
                               fill="papayawhip",
                               hwidth=0.015)
                # outmost polygon contours
                if draw_polygon_edges:
                    d.draw(
                        polygon,
                        transform=trans,
                        hwidth=line_width,
                        fill="darkolivegreen",
                    )

                bar.update(1)

        bar.close()

        # draw the edges with white strips
        if draw_labelled_edges:
            for k, elist in self.edge_indices.items():
                if k != 0:
                    for i, j in elist:
                        p = self.project(self.vertices_coords[i])
                        q = self.project(self.vertices_coords[j])
                        hl = Line.fromPoints(p[0],
                                             p[1],
                                             q[0],
                                             q[1],
                                             segment=True)
                        if k == 1:
                            x = divide_line(line_width, 1)
                            d.draw(hl,
                                   transform=trans,
                                   hwidth=(-x, x),
                                   fill="papayawhip")
                        if k == 2:
                            x1, x2 = divide_line(line_width, 2)
                            d.draw(hl,
                                   transform=trans,
                                   hwidth=(x1, x2),
                                   fill="papayawhip")
                            d.draw(
                                hl,
                                transform=trans,
                                hwidth=(-x2, -x1),
                                fill="papayawhip",
                            )

        # draw vertices with labels
        if show_vertices_labels:
            for i, p in enumerate(self.vertices_coords):
                loc = self.project(p)
                P = Point(*loc)
                d.draw(P,
                       transform=trans,
                       hradius=vertex_size,
                       fill="darkolivegreen")
                Q = trans.applyToTuple(P)
                x_, y_, r_ = get_euclidean_center_radius_uhp(Q, vertex_size)
                d.append(
                    drawSvg.Text(str(i), r_, x_, y_, center=0.7, fill="white"))

        d.append(drawSvg.Rectangle(-20, 0, 40, 0.02, fill="#000"))
        d.setRenderSize(w=image_size[0], h=image_size[1])
        d.saveSvg(output)
        size = os.path.getsize(output) >> 10
        print("{}KB svg file has been written to disk".format(size))
        print("=" * 40)
Exemple #2
0
    def render(
            self,
            output,
            image_size,
            show_vertices_labels=False,
            draw_alternative_domains=True,
            draw_polygon_edges=True,
            draw_inner_lines=False,
            draw_labelled_edges=False,
            vertex_size=0.1,
            line_width=0.07,
            checker=False,
            checker_colors=("#1E7344", "#EAF78D"),
            face_colors=("lightcoral", "mistyrose", "steelblue"),
    ):
        """
        An example drawing function shows how to draw hyperbolic patterns
        with this program.
        """
        print("=" * 40)
        print(self.get_info())
        d = drawSvg.Drawing(2.05, 2.05, origin="center")
        # draw background unit circle
        d.draw(euclid.shapes.Circle(0, 0, 1), fill="silver")

        bar = tqdm.tqdm(desc="processing polygons", total=self.num_faces)

        # draw the faces
        for (i, j), flist in self.face_indices.items():
            if checker:
                style1 = {"fill": checker_colors[0]}
                style2 = {"fill": checker_colors[1]}
            else:
                vertex_index = self.vertex_at_mirrors(i, j)
                color = face_colors[vertex_index]
                style1 = {"fill": color}
                style2 = {"fill": color, "opacity": 0.3}

            for k, face in enumerate(flist):
                # coords of the vertices of this face
                points = [self.project(p) for p in face.coords]
                polygon = Polygon.fromVertices(points)
                # compute the alternate domains
                domain1, domain2 = face.get_alternative_domains()
                domain1_2d = [[self.project(p) for p in D] for D in domain1]
                domain2_2d = [[self.project(p) for p in D] for D in domain2]

                # draw domains of even reflections
                for D in domain1_2d:
                    poly = Polygon.fromVertices(D)
                    d.draw(poly, **style1)
                    if checker:
                        d.draw(poly, hwidth=0.005, **style1)
                    if draw_inner_lines:
                        d.draw(poly, fill="papayawhip", hwidth=0.015)
                # draw domains of odd reflections
                for D in domain2_2d:
                    poly = Polygon.fromVertices(D)
                    d.draw(poly, **style2)
                    if checker:
                        d.draw(poly, hwidth=0.005, **style2)
                    if draw_inner_lines:
                        d.draw(poly, fill="papayawhip", hwidth=0.015)
                # outmost polygon contours
                if draw_polygon_edges:
                    d.draw(polygon, hwidth=line_width, fill="darkolivegreen")

                bar.update(1)

        bar.close()

        # draw the edges with white strips
        if draw_labelled_edges:
            for k, elist in self.edge_indices.items():
                if k != 0:
                    for i, j in elist:
                        p = self.project(self.vertices_coords[i])
                        q = self.project(self.vertices_coords[j])
                        hl = Line.fromPoints(p[0],
                                             p[1],
                                             q[0],
                                             q[1],
                                             segment=True)
                        if k == 1:
                            x = divide_line(line_width, 1)
                            d.draw(hl, hwidth=(-x, x), fill="papayawhip")
                        if k == 2:
                            x1, x2 = divide_line(line_width, 2)
                            d.draw(hl, hwidth=(x1, x2), fill="papayawhip")
                            d.draw(hl, hwidth=(-x2, -x1), fill="papayawhip")

        # draw vertices with labels
        if show_vertices_labels:
            for i, p in enumerate(self.vertices_coords):
                loc = self.project(p)
                P = Point(*loc)
                d.draw(P, hradius=vertex_size, fill="darkolivegreen")
                x, y, r = get_euclidean_center_radius(P,
                                                      hrad=vertex_size * 1.3)
                d.draw(drawSvg.Text(str(i), r, x, y, center=0.7, fill="white"))

        print("saving to svg...")
        d.setRenderSize(w=image_size)
        d.saveSvg(output)
        size = os.path.getsize(output) >> 10
        print("{}KB svg file has been written to disk".format(size))
        print("=" * 40)