當前位置: 首頁>>代碼示例>>Python>>正文


Python canoepaddle.Pen類代碼示例

本文整理匯總了Python中canoepaddle.Pen的典型用法代碼示例。如果您正苦於以下問題:Python Pen類的具體用法?Python Pen怎麽用?Python Pen使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Pen類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: draw_character

    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
開發者ID:christian-oudard,項目名稱:ithkuil,代碼行數:25,代碼來源:consonant.py

示例2: test_text_centered

def test_text_centered():
    p = Pen()
    p.move_to((0, 0))
    p.text('abcd', 1, 'sans-serif', centered=True)
    svg_data = p.paper.format_svg(0)
    assert (
        '<text x="0" y="0" font-family="sans-serif" font-size="1" '
        'fill="#000000" text-anchor="middle">abcd</text>'
    ) in svg_data
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:9,代碼來源:test_text.py

示例3: test_draw_bounds

def test_draw_bounds():
    p = Pen()
    p.fill_mode()
    Bounds(-2, -3, 1, 2).draw(p)

    assert_path_data(
        p, 0,
        'M-2,3 L1,3 L1,-2 L-2,-2 L-2,3 z'
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:9,代碼來源:test_bounds.py

示例4: test_text

def test_text():
    p = Pen()
    p.move_to((0, 0))
    p.text('abcd', 1, 'sans-serif')
    svg_data = p.paper.format_svg(0)
    assert (
        '<text x="0" y="0" font-family="sans-serif" font-size="1" '
        'fill="#000000">abcd</text>'
    ) in svg_data
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:9,代碼來源:test_text.py

示例5: handle_letter

def handle_letter(letter, mode):
    letter_paper = draw_letter(
        letter,
        mode,
        fixed_width=30.0,
        show_template=True,
        fuse=False,
    )
    letter_paper.translate((5, 0), bounds=False)

    p = Pen()
    p.move_to((-8, 3))
    p.text(
        letter.case,
        6.0,
        font,
        gray,
        centered=True,
    )
    p.move_to((-8, -3))
    p.text(
        ', '.join(lookup(letter.case)),
        6.0,
        font,
        gray,
        centered=True,
    )
    letter_paper.merge(p.paper)

    return letter_paper
開發者ID:christian-oudard,項目名稱:ithkuil,代碼行數:30,代碼來源:primary_characters.py

示例6: test_copy_no_mode

def test_copy_no_mode():
    p = Pen()
    assert_raises(
        AttributeError,
        lambda: p.mode
    )
    p = p.copy()
    assert_raises(
        AttributeError,
        lambda: p.mode
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:11,代碼來源:test_copy.py

示例7: test_copy_arc_to

def test_copy_arc_to():
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(0)
    p.arc_to((5, 5))
    p = p.copy(paper=True)

    assert_path_data(
        p, 0,
        'M0,0 A 5,5 0 0 0 5,-5'
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:12,代碼來源:test_copy.py

示例8: test_text_translate

def test_text_translate():
    p = Pen()
    p.move_to((0, 0))
    p.text('abcd', 1)
    paper = p.paper

    paper.translate((2, 3))
    svg_data = paper.format_svg(0)
    assert (
        '<text x="2" y="-3" font-family="sans-serif" font-size="1" '
        'fill="#000000">abcd</text>'
    ) in svg_data
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:12,代碼來源:test_text.py

示例9: draw_letter

def draw_letter(
    letter,
    mode,
    fixed_width=None,
    show_template=False,
    show_bounds=False,
    fuse=True,
):
    """
    Draw the given letter and return a Paper.

    The letter is located centered on x=0, and with y=0 as the
    character baseline.

    If `fixed_width` is specified, use that for the paper width.
    """
    if DEBUG_OUTPUT:
        print(str(letter), file=sys.stderr)

    try:
        character_paper = letter.draw_character(mode, fuse=fuse)
    except Exception:
        if DEBUG_OUTPUT:
            traceback.print_exc()
            # Return an error pattern.
            pen = Pen()
            pen.fill_mode()
            pen.square(1)
            character_paper = pen.paper
        else:
            raise

    if fixed_width is not None:
        bounds = character_paper.bounds()
        bounds.left = -fixed_width / 2
        bounds.right = +fixed_width / 2
        character_paper.override_bounds(bounds)

    template_paper = Paper()
    if show_template:
        template_paper = draw_template_path()
    else:
        template_paper = Paper()

    letter_paper = Paper()
    letter_paper.merge(template_paper)
    letter_paper.merge(character_paper)

    # Set proper bounds for typesetting. Use the character bounds as our basis
    # so the template doesn't increase the size.
    bounds = character_paper.bounds()
    letter_paper.override_bounds(bounds)

    if show_bounds:
        pen = Pen()
        pen.fill_mode('#aaa')
        bounds.draw(pen)
        letter_paper.merge_under(pen.paper)

    return letter_paper
開發者ID:christian-oudard,項目名稱:ithkuil,代碼行數:60,代碼來源:typeset.py

示例10: test_copy_loop

def test_copy_loop():
    p = Pen()
    p.stroke_mode(0.2)

    def square():
        p.turn_to(180)
        p.line_forward(1)
        p.turn_left(90)
        p.line_forward(1)
        p.turn_left(90)
        p.line_forward(1)
        p.turn_left(90)
        p.line_forward(1)

    p.move_to((0, 0))
    square()
    p = p.copy(paper=True)
    p.move_to((2, 0))
    square()

    assert_path_data(
        p, 1,
        (
            'M0.1,-0.1 L-1.1,-0.1 L-1.1,1.1 L0.1,1.1 L0.1,-0.1 z '
            'M-0.1,0.1 L-0.1,0.9 L-0.9,0.9 L-0.9,0.1 L-0.1,0.1 z '
            'M2.1,-0.1 L0.9,-0.1 L0.9,1.1 L2.1,1.1 L2.1,-0.1 z '
            'M1.9,0.1 L1.9,0.9 L1.1,0.9 L1.1,0.1 L1.9,0.1 z'
        )
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:29,代碼來源:test_copy.py

示例11: test_text_merge

def test_text_merge():
    p = Pen()
    p.move_to((0, 0))
    p.text('abcd', 1)
    paper1 = p.paper
    assert '<text' in paper1.format_svg(0)

    paper2 = Paper()
    paper2.merge(paper1)
    assert '<text' in paper2.format_svg(0)

    paper3 = Paper()
    paper3.merge_under(paper1)
    assert '<text' in paper3.format_svg(0)
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:14,代碼來源:test_text.py

示例12: test_translate_override_bounds

def test_translate_override_bounds():
    # Translate a paper that has overridden bounds. The bounds update as well.
    paper = Paper()
    paper.override_bounds(0, 0, 1, 1)
    paper.translate((3, 4))
    assert_equal(
        paper.bounds(),
        Bounds(3, 4, 4, 5)
    )

    # When bounds=False is passed, then the bounds do not update.
    paper = Paper()
    paper.override_bounds(0, 0, 1, 1)
    paper.translate((3, 4), bounds=False)
    assert_equal(paper.bounds(), Bounds(0, 0, 1, 1))

    # This also works if the bounds are not overridden.
    p = Pen()
    p.fill_mode()
    p.move_to((0.5, 0.5))
    p.circle(0.5)
    assert_equal(p.paper.bounds(), Bounds(0, 0, 1, 1))

    p.paper.translate((3, 4), bounds=False)

    assert_equal(p.paper.bounds(), Bounds(0, 0, 1, 1))
    assert_equal(p.last_path().bounds(), Bounds(3, 4, 4, 5))
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:27,代碼來源:test_paper.py

示例13: test_copy_no_paper

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'
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:17,代碼來源:test_copy.py

示例14: test_override_bounds_copy

def test_override_bounds_copy():
    # Get the bounds of a Paper, modify them, then set them back changed.
    paper = Paper()
    paper.override_bounds(0, 0, 1, 1)

    bounds = paper.bounds()
    bounds.right = 5

    assert_equal(paper.bounds(), Bounds(0, 0, 1, 1))
    paper.override_bounds(bounds)
    assert_equal(paper.bounds(), Bounds(0, 0, 5, 1))

    # This works on non-overridden Papers as well.
    paper = Paper()

    p = Pen()
    p.fill_mode()
    p.move_to((0.5, 0.5))
    p.circle(0.5)

    bounds = p.paper.bounds()
    bounds.right = 5

    assert_equal(p.paper.bounds(), Bounds(0, 0, 1, 1))
    p.paper.override_bounds(bounds)
    assert_equal(p.paper.bounds(), Bounds(0, 0, 5, 1))
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:26,代碼來源:test_paper.py

示例15: test_copy_arc

def test_copy_arc():
    p1 = Pen()
    p1.fill_mode()

    p1.move_to((0, 0))
    p1.turn_to(0)
    p1.arc_left(90, radius=5)

    p2 = p1.copy(paper=True)
    p2.arc_left(90, radius=5)

    assert_path_data(
        p1, 0,
        'M0,0 A 5,5 0 0 0 5,-5'
    )
    assert_path_data(
        p2, 0,
        'M0,0 A 5,5 0 0 0 5,-5 A 5,5 0 0 0 0,-10'
    )
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:19,代碼來源:test_copy.py


注:本文中的canoepaddle.Pen類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。