当前位置: 首页>>代码示例>>Python>>正文


Python pen.Pen类代码示例

本文整理汇总了Python中canoepaddle.pen.Pen的典型用法代码示例。如果您正苦于以下问题:Python Pen类的具体用法?Python Pen怎么用?Python Pen使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Pen类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_mode_error

def test_mode_error():
    p = Pen()
    # Don't set a mode.
    assert_raises(
        AttributeError,
        lambda: p.line_forward(1)
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:7,代码来源:test_pen.py

示例2: test_circle_degenerate

def test_circle_degenerate():
    p = Pen()
    p.stroke_mode(2.0)
    p.circle(1)
    assert_equal(
        p.paper.svg_elements(0),
        ['<path d="M2,0 A 2,2 0 0 0 -2,0 A 2,2 0 0 0 2,0 z" fill="#000000" />']
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:8,代码来源:test_pen.py

示例3: test_circle

def test_circle():
    p = Pen()
    p.fill_mode()
    p.circle(1)

    assert_equal(
        p.paper.svg_elements(0),
        ['<path d="M1,0 A 1,1 0 0 0 -1,0 A 1,1 0 0 0 1,0 z" fill="#000000" />']
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:9,代码来源:test_pen.py

示例4: test_color_formats

def test_color_formats():
    for color, output in [
        (
            (1.0, 0.0, 0.0),
            '#ff0000',
        ),
        (
            Color.NewFromHtml('red'),
            '#ff0000',
        ),
        (
            'green',
            '#008000',
        ),
        (
            '#123456',
            '#123456',
        ),
    ]:
        p = Pen()
        p.stroke_mode(2.0, color)
        p.move_to((0, 0))
        p.turn_to(0)
        p.line_forward(5)

        assert_equal(
            p.paper.svg_elements(0)[0],
            '<path d="M0,-1 L0,1 L5,1 L5,-1 L0,-1 z" fill="{}" />'.format(output)
        )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:29,代码来源:test_pen.py

示例5: draw

 def draw(offset):
     p = Pen()
     p.stroke_mode(1.0)
     p.move_to((0, 0))
     p.turn_to(0)
     p.line_forward(0.5 + offset, end_slant=45)
     return p
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:7,代码来源:test_segment.py

示例6: test_straight_joint_headings

def test_straight_joint_headings():
    # The math in calculating joint geometry can get numerically unstable
    # very close to straight joints at various headings.
    for heading_angle in range(0, 45):
        p = Pen()
        p.stroke_mode(1.0)
        p.move_to((0, 0))
        p.turn_to(heading_angle)
        p.line_forward(10)
        p.line_forward(10)

        path = p.paper.paths[0]
        path.render_path(2)  # Doesn't crash.

        # Check that the joint angle is 90 degrees from the heading.
        assert_equal(len(p.paper.paths), 1)
        segments = p.paper.paths[0].segments
        assert_equal(len(segments), 2)
        s0, s1 = segments

        target_angle = (heading_angle + 90) % 180

        joint_angle = math.degrees(vec.heading(vec.vfrom(s0.b_right, s0.b_left)))
        assert_almost_equal(joint_angle % 180, target_angle)

        joint_angle = math.degrees(vec.heading(vec.vfrom(s1.a_right, s1.a_left)))
        assert_almost_equal(joint_angle % 180, target_angle)
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:27,代码来源:test_pen.py

示例7: test_arc_error

def test_arc_error():
    # Don't allow drawing an arc without a center or radius.
    p = Pen()
    assert_raises(
        TypeError,
        lambda: p.arc_left(90)
    )
    assert_raises(
        TypeError,
        lambda: p.arc_right(90)
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:11,代码来源:test_pen.py

示例8: test_line

def test_line():
    p = Pen()
    p.fill_mode()
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)

    assert_path_data(
        p, 0,
        'M0,0 L5,0'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:11,代码来源:test_pen.py

示例9: test_degenerate_arc

def test_degenerate_arc():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_to(
        (5, 0),
        center=(0, -200),
        start_slant=-5,
        end_slant=5,
    )
    seg = p.last_segment()
    assert seg.start_joint_illegal
    assert seg.end_joint_illegal
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:15,代码来源:test_segment.py

示例10: test_line_segments

def test_line_segments():
    p = Pen()
    p.fill_mode()

    p.move_to((0, 0))
    p.turn_to(45)
    p.line_forward(2.0)

    assert_points_equal(p.position, (sqrt2, sqrt2))
    assert_equal(len(p.paper.paths), 1)
    segments = p.last_path().segments
    for actual, target in zip(segments, [
        ((0, 0), (sqrt2, sqrt2)),
    ]):
        assert_segments_equal(actual, target)
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:15,代码来源:test_segment.py

示例11: test_straight_joint

def test_straight_joint():
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(3)
    p.line_forward(3)

    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L3,1 L6,1 L6,-1 L3,-1 L0,-1 z'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:12,代码来源:test_pen.py

示例12: test_arc_sweep_bug

def test_arc_sweep_bug():
    p = Pen()
    p.stroke_mode(2.0)

    p.move_to((3, 0))
    p.turn_to(90)
    p.arc_left(270, 3)

    assert_path_data(
        p, 0,
        'M2,0 L4,0 A 4,4 0 1 0 0,4 L0,2 A 2,2 0 1 1 2,0 z'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:12,代码来源:test_pen.py

示例13: test_arc_normalize

def test_arc_normalize():
    # Arc angles larger than 360 behave correctly.
    p = Pen()
    p.fill_mode()
    p.move_to((-5, 0))
    p.turn_to(0)
    p.arc_left(360 + 90, radius=5)

    assert_path_data(
        p, 0,
        'M-5,0 A 5,5 0 0 0 0,-5'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:12,代码来源:test_pen.py

示例14: test_arc_pie_slice

def test_arc_pie_slice():
    # Draw a "pie slice" arc that is wide enough to reach all the way to the
    # arc center.
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0.5, 0))
    p.turn_to(90)
    p.arc_left(90, 0.5)

    assert_path_data(
        p, 0,
        'M0,0 L1,0 A 1,1 0 0 0 0,-1 L0,0 z'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:13,代码来源:test_pen.py

示例15: test_zero_length_side

def test_zero_length_side():
    # It is possible and legal to create a segment that just barely goes to
    # zero on one side.
    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(1.0, end_slant=45)

    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L2,-1 L0,-1 z',
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:13,代码来源:test_pen.py


注:本文中的canoepaddle.pen.Pen类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。