Example #1
0
def main(name):
    """
    Some examples how to use the shapes extension
    """
    dwg = svgwrite.Drawing(name + ".svg", (1000, 1000), debug=True)
    style = {"fill": "none", "stroke": "black", "stroke-width": "1"}
    # create a list of points lying on the corners of an octagon
    octagon = list(ngon(8, edge_length=10, rotation=math.pi / 8))
    dwg.add(dwg.polygon(octagon, **style))
    # translate it
    octagon_translated = list(translate(octagon, 100, 100))
    dwg.add(dwg.polygon(octagon_translated, **style))
    # rotate it
    octagon_rotated = list(
        rotate(translate(octagon_translated, 10, 10), math.pi / 8))
    dwg.add(dwg.polygon(octagon_rotated, **style))
    # scale it
    # make sure first to scale it, then to translate it
    octagon_scaled = list(translate(scale(octagon, 10, 10), 500, 500))
    dwg.add(dwg.polygon(octagon_scaled, **style))

    dwg.add(
        dwg.polygon(translate(star(5, 50, 20, rotation=-math.pi / 2), 400,
                              100)))
    dwg.save(pretty=True)
Example #2
0
def test_square_by_radius():
    corners = list(ngon(4, radius=1))
    assert len(corners) == 4
    assert are_close_points(corners[0], (1, 0))
    assert are_close_points(corners[1], (0, 1))
    assert are_close_points(corners[2], (-1, 0))
    assert are_close_points(corners[3], (0, -1))
Example #3
0
def test_heptagon_by_edge_length():
    corners = list(ngon(7, edge_length=10))
    assert len(corners) == 7
    assert are_close_points(corners[0], (11.523824354812433, 0.0))
    assert are_close_points(corners[1], (7.184986963636852, 9.009688679024192))
    assert are_close_points(corners[2],
                            (-2.564292158181384, 11.234898018587335))
    assert are_close_points(corners[3], (-10.382606982861683, 5.0))
    assert are_close_points(corners[4], (-10.382606982861683, -5))
    assert are_close_points(corners[5],
                            (-2.564292158181387, -11.234898018587335))
    assert are_close_points(corners[6], (7.18498696363685, -9.009688679024192))
Example #4
0
def test_centroid():
    assert are_close_points(centroid(ngon(7, edge_length=10)), (0, 0))