def test_path_and_fill(canvas):
    canvas.draw_path([Point(0, 0), Point(0.5, 0.5),
                      Point(1, 0)],
                     close_path=True)
    canvas.fill()
    canvas.stroke()
    canvas.clip()
def test_point_from_polar():
    assert Point(0, 0) == Point.from_polar(0, 0)
    assert Point(0, 0) == Point.from_polar(0, 1)
    assert Point(1, 0) == Point.from_polar(1, 0)
    assert pytest.approx(list(Point(-2, 0))) == list(Point.from_polar(2, pi))
    assert pytest.approx(list(Point(1, 1))) == list(
        Point.from_polar(sqrt(2), pi / 4))
Esempio n. 3
0
def main() -> None:
    circles = []
    for i, j in product(range(1, N + 1), repeat=2):
        circle = Circle(Point(i / (N + 1), j / (N + 1)), 1 / (3 * (N + 1)))
        circles.append(circle)

    canvas = Canvas(RESOLUTION, RESOLUTION)
    canvas.set_background(WHITE)
    canvas.set_black()
    canvas.set_line_width(0.01)
    for circle in circles:
        canvas.draw_circle(circle)
        canvas.stroke()

    dir_path = os.path.dirname(os.path.realpath(__file__))
    canvas.write_to_png(f"{dir_path}/output/circles.png")
Esempio n. 4
0
def main():
    canvas = Canvas(RESOLUTION)

    canvas.set_background(WHITE)

    canvas.set_black()
    canvas.set_line_width(0.1)

    canvas.set_line_cap(LineCap.ROUND)
    canvas.draw_path([Point(1 / 4, 1 / 4), Point(1 / 4, 3 / 4)])
    canvas.stroke()

    canvas.set_line_cap(LineCap.BUTT)
    canvas.draw_path([Point(1 / 2, 1 / 4), Point(1 / 2, 3 / 4)])
    canvas.stroke()

    canvas.set_line_cap(LineCap.SQUARE)
    canvas.draw_path([Point(3 / 4, 1 / 4), Point(3 / 4, 3 / 4)])
    canvas.stroke()

    dir_path = os.path.dirname(os.path.realpath(__file__))
    canvas.write_to_png(f"{dir_path}/output/lines.png")
def test_circle(canvas, fill, stroke):
    canvas.draw_circle(Circle(Point(0.5, 0.5), 0.1), fill=fill, stroke=stroke)
def get_points(dt: float) -> Iterable[Point]:
    for t in float_range(0, 1, dt):
        yield Point(t, sin(2 * pi * t) / 3 + 1 / 2)
def test_polygon():
    p = Polygon((0, 0), (1, 1))
    assert p.get_centre() == Point(0.5, 0.5)
    assert [Point(0, 0), Point(1, 1)] == list(p)
def test_circle():
    assert Circle(Point(1, 1), 1).intersects(Circle(Point(0, 0), 1))
    assert not Circle(Point(1, 1), 0.5).intersects(Circle(Point(0, 0), 0.5))
def test_point():
    assert Point(1, 1) == Point(1, 0) + Point(0, 1)
    assert Point(2, 1) - Point(1, 1) == Point(1, 0)
    assert (0, 1) == tuple(Point(0, 1))