Beispiel #1
0
def test_translate():
    p = Pen()
    p.stroke_mode(1.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(3)
    p.arc_left(90, 3)
    p.turn_left(90)
    p.move_forward(3)
    p.fill_mode()
    p.circle(0.5)
    p.move_forward(3)
    p.square(1)

    p.paper.translate((1, 1))

    assert_equal(p.paper.svg_elements(1), [
        ('<path d="M1.0,-1.5 L1.0,-0.5 L4.0,-0.5 A 3.5,3.5 0 0 0 '
         '7.5,-4.0 L6.5,-4.0 A 2.5,2.5 0 0 1 4.0,-1.5 L1.0,-1.5 z" '
         'fill="#000000" />'),
        ('<path d="M4.5,-4.0 A 0.5,0.5 0 0 0 3.5,-4.0 '
         'A 0.5,0.5 0 0 0 4.5,-4.0 z" fill="#000000" />'),
        ('<path d="M0.5,-3.5 L1.5,-3.5 L1.5,-4.5 L0.5,-4.5 L0.5,-3.5 z" '
         'fill="#000000" />'),
    ])
def test_copy_log():
    p1 = Pen()
    p1.fill_mode()
    p1.move_to((0, 0))
    p1.turn_to(0)
    p1.line_forward(5)
    p2 = p1.copy(paper=True)
    p2.line_forward(5)

    assert_equal(
        p1.log(),
        [
            'fill_mode()', 'move_to((0, 0))', 'turn_to(0)', 'line_forward(5)',
        ]
    )
    assert_path_data(
        p1, 0,
        'M0,0 L5,0'
    )
    assert_equal(
        p2.log(),
        [
            'fill_mode()', 'move_to((0, 0))', 'turn_to(0)', 'line_forward(5)',
            'line_forward(5)',
        ]
    )
    assert_path_data(
        p2, 0,
        'M0,0 L5,0 L10,0'
    )
def test_center_on_xy():
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(4)

    p.move_to((2, 1))
    p.circle(1)

    p.paper.center_on_x(0)

    assert_equal(
        p.paper.svg_elements(0),
        [
            '<path d="M-2,-1 L-2,1 L2,1 L2,-1 L-2,-1 z" fill="#000000" />',
            '<path d="M2,-1 A 2,2 0 0 0 -2,-1 A 2,2 0 0 0 2,-1 z" fill="#000000" />',
        ]
    )

    p.paper.center_on_y(0)

    assert_equal(
        p.paper.svg_elements(1),
        [
            (
                '<path d="M-2.0,0.0 L-2.0,2.0 L2.0,2.0 L2.0,0.0 L-2.0,0.0 z" '
                'fill="#000000" />'
            ),
            (
                '<path d="M2.0,0.0 A 2.0,2.0 0 0 0 -2.0,0.0 '
                'A 2.0,2.0 0 0 0 2.0,0.0 z" fill="#000000" />'
            ),
        ]
    )
Beispiel #4
0
    def draw_character(self, mode, **kwargs):
        side_ending = self.side_ending_class(
            self,
            self.side_flipped,
        )

        paper = Paper()

        pen = Pen()
        pen.set_mode(mode)
        pen.move_to((0, TOP - mode.width / 2))
        pen.turn_to(0)
        pen.line_forward(2.0)
        pen.last_segment().start_cap = stub_cap

        side_ending.draw(pen)
        paper.merge(pen.paper)

        bounds = paper.bounds()
        bounds.top = OVER
        bounds.bottom = MIDDLE
        bounds.left = 0
        paper.override_bounds(bounds)

        return paper
def test_mirror_end_slant():
    paper = Paper()

    p = Pen()
    p.stroke_mode(sqrt2)
    p.move_to((0, 0))
    p.turn_to(-45)
    p.line_forward(5 * sqrt2, end_slant=45)
    p.paper.mirror_x(0)
    paper.merge(p.paper)

    p = Pen()
    p.stroke_mode(sqrt2)
    p.move_to((0, 0))
    p.turn_to(45)
    p.line_forward(5 * sqrt2)
    paper.merge(p.paper)

    paper.join_paths()
    paper.fuse_paths()

    assert_path_data(
        paper, 1,
        'M-5.5,4.5 L-4.5,5.5 L5.5,-4.5 L4.5,-5.5 L-5.5,4.5 z'
    )
def test_translate():
    p = Pen()
    p.stroke_mode(1.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(3)
    p.arc_left(90, 3)
    p.turn_left(90)
    p.move_forward(3)
    p.fill_mode()
    p.circle(0.5)
    p.move_forward(3)
    p.square(1)

    p.paper.translate((1, 1))

    assert_equal(
        p.paper.svg_elements(1),
        [
            (
                '<path d="M1.0,-1.5 L1.0,-0.5 L4.0,-0.5 A 3.5,3.5 0 0 0 '
                '7.5,-4.0 L6.5,-4.0 A 2.5,2.5 0 0 1 4.0,-1.5 L1.0,-1.5 z" '
                'fill="#000000" />'
            ),
            (
                '<path d="M4.5,-4.0 A 0.5,0.5 0 0 0 3.5,-4.0 '
                'A 0.5,0.5 0 0 0 4.5,-4.0 z" fill="#000000" />'
            ),
            (
                '<path d="M0.5,-3.5 L1.5,-3.5 L1.5,-4.5 L0.5,-4.5 L0.5,-3.5 z" '
                'fill="#000000" />'
            ),
        ]
    )
Beispiel #7
0
    def draw_character(self, mode, **kwargs):
        side_ending = self.side_ending_class(
            self,
            self.side_flipped,
        )

        paper = Paper()

        pen = Pen()
        pen.set_mode(mode)
        pen.move_to((0, TOP - mode.width / 2))
        pen.turn_to(0)
        pen.line_forward(2.0)
        pen.last_segment().start_cap = stub_cap

        side_ending.draw(pen)
        paper.merge(pen.paper)

        bounds = paper.bounds()
        bounds.top = OVER
        bounds.bottom = MIDDLE
        bounds.left = 0
        paper.override_bounds(bounds)

        return paper
Beispiel #8
0
def test_center_on_xy():
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(4)

    p.move_to((2, 1))
    p.circle(1)

    p.paper.center_on_x(0)

    assert_equal(p.paper.svg_elements(0), [
        '<path d="M-2,-1 L-2,1 L2,1 L2,-1 L-2,-1 z" fill="#000000" />',
        '<path d="M2,-1 A 2,2 0 0 0 -2,-1 A 2,2 0 0 0 2,-1 z" fill="#000000" />',
    ])

    p.paper.center_on_y(0)

    assert_equal(p.paper.svg_elements(1), [
        ('<path d="M-2.0,0.0 L-2.0,2.0 L2.0,2.0 L2.0,0.0 L-2.0,0.0 z" '
         'fill="#000000" />'),
        ('<path d="M2.0,0.0 A 2.0,2.0 0 0 0 -2.0,0.0 '
         'A 2.0,2.0 0 0 0 2.0,0.0 z" fill="#000000" />'),
    ])
def test_copy_no_paper():
    p1 = Pen()
    p1.fill_mode()
    p1.move_to((0, 0))
    p1.turn_to(0)
    p1.line_forward(5)
    p2 = p1.copy()
    p2.line_forward(5)

    assert_path_data(p1, 0, 'M0,0 L5,0')
    assert_path_data(p2, 0, 'M5,0 L10,0')
Beispiel #10
0
def test_join_paths_thick():
    # Segments join together if possible when join_paths is called.
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.break_stroke()
    p.turn_left(90)
    p.line_forward(5)
    p.paper.join_paths()
    assert_path_data(p, 0, 'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z')
Beispiel #11
0
def test_fuse_paths():
    # Create two halves of a stroke in the same direction.
    p = Pen()
    p.stroke_mode(sqrt2)

    p.move_to((-3, 3))
    p.turn_to(-45)
    p.line_forward(3 * sqrt2, start_slant=0)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.paper.fuse_paths()

    assert_path_data(p, 1,
                     ['M-2.0,-3.0 L-4.0,-3.0 L2.0,3.0 L4.0,3.0 L-2.0,-3.0 z'])
def test_join_paths_thick():
    # Segments join together if possible when join_paths is called.
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.break_stroke()
    p.turn_left(90)
    p.line_forward(5)
    p.paper.join_paths()
    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z'
    )
def test_fuse_paths():
    # Create two halves of a stroke in the same direction.
    p = Pen()
    p.stroke_mode(sqrt2)

    p.move_to((-3, 3))
    p.turn_to(-45)
    p.line_forward(3 * sqrt2, start_slant=0)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.paper.fuse_paths()

    assert_path_data(
        p, 1,
        ['M-2.0,-3.0 L-4.0,-3.0 L2.0,3.0 L4.0,3.0 L-2.0,-3.0 z']
    )
def test_copy_no_paper():
    p1 = Pen()
    p1.fill_mode()
    p1.move_to((0, 0))
    p1.turn_to(0)
    p1.line_forward(5)
    p2 = p1.copy()
    p2.line_forward(5)

    assert_path_data(
        p1, 0,
        'M0,0 L5,0'
    )
    assert_path_data(
        p2, 0,
        'M5,0 L10,0'
    )
Beispiel #15
0
def test_join_paths_turn_back_no_joint():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(10)
    p.turn_right(180)
    p.break_stroke()
    p.line_forward(5)
    p.paper.join_paths()

    line1, line2 = p.last_path().segments
    assert line1.end_joint_illegal
    assert line2.start_joint_illegal

    assert_path_data(p, 1,
                     ('M0.0,-0.5 L0.0,0.5 L10.0,0.5 L10.0,-0.5 '
                      'L5.0,-0.5 L5.0,0.5 L10.0,0.5 L10.0,-0.5 L0.0,-0.5 z'))
def test_copy_custom_cap():
    # Regression test for a bug where doing pen.copy() in a cap function would
    # break outline drawing.
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    def copy_cap(pen, end):
        pen.copy()
        pen.line_to(end)

    p.last_segment().end_cap = copy_cap

    assert_path_data(p, 0, 'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z')
Beispiel #17
0
def test_join_and_fuse_simple():
    # Create two halves of a stroke in separate directions.
    p = Pen()
    p.stroke_mode(sqrt2)

    p.move_to((0, 0))
    p.turn_to(-45)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.break_stroke()

    p.move_to((0, 0))
    p.turn_to(-45 + 180)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.paper.join_paths()
    p.paper.fuse_paths()

    assert_path_data(p, 1,
                     'M2.0,3.0 L4.0,3.0 L-2.0,-3.0 L-4.0,-3.0 L2.0,3.0 z')
def test_fuse_with_joint():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(180)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    p.break_stroke()

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)

    assert_path_data(
        p, 0,
        [
            'M0,1 L0,-1 L-6,-1 L-6,5 L-4,5 L-4,1 L0,1 z',
            'M0,-1 L0,1 L5,1 L5,-1 L0,-1 z',
        ]
    )

    p.paper.join_paths()
    p.paper.fuse_paths()

    assert_path_data(
        p, 0,
        'M-6,5 L-4,5 L-4,1 L5,1 L5,-1 L-6,-1 L-6,5 z'
    )
Beispiel #19
0
def test_fuse_with_joint():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(180)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    p.break_stroke()

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)

    assert_path_data(p, 0, [
        'M0,1 L0,-1 L-6,-1 L-6,5 L-4,5 L-4,1 L0,1 z',
        'M0,-1 L0,1 L5,1 L5,-1 L0,-1 z',
    ])

    p.paper.join_paths()
    p.paper.fuse_paths()

    assert_path_data(p, 0, 'M-6,5 L-4,5 L-4,1 L5,1 L5,-1 L-6,-1 L-6,5 z')
def test_join_paths_turn_back_no_joint():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(10)
    p.turn_right(180)
    p.break_stroke()
    p.line_forward(5)
    p.paper.join_paths()

    line1, line2 = p.last_path().segments
    assert line1.end_joint_illegal
    assert line2.start_joint_illegal

    assert_path_data(
        p, 1,
        (
            'M0.0,-0.5 L0.0,0.5 L10.0,0.5 L10.0,-0.5 '
            'L5.0,-0.5 L5.0,0.5 L10.0,0.5 L10.0,-0.5 L0.0,-0.5 z'
        )
    )
def test_copy_custom_cap():
    # Regression test for a bug where doing pen.copy() in a cap function would
    # break outline drawing.
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)

    def copy_cap(pen, end):
        pen.copy()
        pen.line_to(end)

    p.last_segment().end_cap = copy_cap

    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L6,1 L6,-5 L4,-5 L4,-1 L0,-1 z'
    )
def test_join_and_fuse_simple():
    # Create two halves of a stroke in separate directions.
    p = Pen()
    p.stroke_mode(sqrt2)

    p.move_to((0, 0))
    p.turn_to(-45)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.break_stroke()

    p.move_to((0, 0))
    p.turn_to(-45 + 180)
    p.line_forward(3 * sqrt2, end_slant=0)

    p.paper.join_paths()
    p.paper.fuse_paths()

    assert_path_data(
        p, 1,
        'M2.0,3.0 L4.0,3.0 L-2.0,-3.0 L-4.0,-3.0 L2.0,3.0 z'
    )
Beispiel #23
0
def test_mirror_end_slant():
    paper = Paper()

    p = Pen()
    p.stroke_mode(sqrt2)
    p.move_to((0, 0))
    p.turn_to(-45)
    p.line_forward(5 * sqrt2, end_slant=45)
    p.paper.mirror_x(0)
    paper.merge(p.paper)

    p = Pen()
    p.stroke_mode(sqrt2)
    p.move_to((0, 0))
    p.turn_to(45)
    p.line_forward(5 * sqrt2)
    paper.merge(p.paper)

    paper.join_paths()
    paper.fuse_paths()

    assert_path_data(paper, 1,
                     'M-5.5,4.5 L-4.5,5.5 L5.5,-4.5 L4.5,-5.5 L-5.5,4.5 z')
def test_copy_log():
    p1 = Pen()
    p1.fill_mode()
    p1.move_to((0, 0))
    p1.turn_to(0)
    p1.line_forward(5)
    p2 = p1.copy(paper=True)
    p2.line_forward(5)

    assert_equal(p1.log(), [
        'fill_mode()',
        'move_to((0, 0))',
        'turn_to(0)',
        'line_forward(5)',
    ])
    assert_path_data(p1, 0, 'M0,0 L5,0')
    assert_equal(p2.log(), [
        'fill_mode()',
        'move_to((0, 0))',
        'turn_to(0)',
        'line_forward(5)',
        'line_forward(5)',
    ])
    assert_path_data(p2, 0, 'M0,0 L5,0 L10,0')
Beispiel #25
0
def draw_template_path():
    pen = Pen()
    pen.stroke_mode(0.05, '#466184')
    pen.turn_to(0)
    pen.move_to((0, BOTTOM))
    pen.line_forward(10)
    pen.move_to((0, MIDDLE))
    pen.line_forward(10)
    pen.move_to((0, TOP))
    pen.line_forward(10)
    pen.paper.center_on_x(0)
    return pen.paper