예제 #1
0
    def test_canvas_shapes(self):
        b0 = Blok([Point(10, 11), Point(12, 13), Point(13, 11)])
        nb0 = Blok.normalize(b0)
        c1 = Canvas(width=20, height=20)
        shape_b0 = PolygonShape(b0.points)
        shape_nb0 = PolygonShape(nb0.points, style=Style(color='red'))
        bbox = shape_nb0.bounding_box()
        path = bbox.get_path()
        shape_bb = PolygonShape(path, style=Style(color='blue'))

        c2 = Canvas.add_shape(c1, shape_b0)
        c3 = Canvas.add_shape(c2, shape_nb0)
        c4 = Canvas.add_shape(c3, shape_bb)

        box = Box(Point(10, 0), Point(20, 10))
        c5 = Canvas.add_shape2(
            c4, PolygonShape(nb0.points, style=Style(color='green')), box)
        box2 = Box(Point(10, 10), Point(20, 20))
        c6 = Canvas.add_shape2(
            c5, PolygonShape(nb0.points, style=Style(color='yellow')), box2)

        with open('canvas1.svg', 'w') as fd:
            Canvas.render_as_svg(c6, file=fd)
예제 #2
0
    def test_canvas_shapes2(self):
        b0 = Blok([Point(10, 11), Point(12, 13), Point(13, 11)])
        nb0 = Blok.normalize(b0)

        c1 = Canvas(width=20, height=20)
        shape_b0 = PolygonShape(b0.points, style=Style(color='green'))
        shape_nb0 = PolygonShape(nb0.points, style=Style(color='red'))

        shape_c1 = CompositeShape([shape_b0, shape_nb0])

        c1 = Canvas.add_shape(c1, shape_c1)

        box = Box(Point(10, 0), Point(20, 10))

        c2 = Canvas.add_shape2(c1, shape_c1, box)
        c3 = Canvas.add_shape2(c2, shape_c1, Box(Point(10, 10), Point(12, 12)))

        with open('canvas2.1.svg', 'w') as fd:
            Canvas.render_as_svg(c3, file=fd)