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


Python Pen.stroke_mode方法代码示例

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


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

示例1: test_straight_joint_headings

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:29,代码来源:test_pen.py

示例2: test_arc_joint_continue

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_arc_joint_continue():
    p = Pen()
    p.stroke_mode(2.0)

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

    p.arc_left(90, 5)
    p.arc_left(90, 5)

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

    p.arc_right(90, 5)
    p.arc_right(90, 5)

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

示例3: draw

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
 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,代码行数:9,代码来源:test_segment.py

示例4: test_joint_loop_multiple

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_joint_loop_multiple():
    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.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,代码行数:30,代码来源:test_pen.py

示例5: test_color_formats

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:31,代码来源:test_pen.py

示例6: test_joint_loop_color

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_joint_loop_color():
    p = Pen()

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

    # Draw a square with one side a different color. It joins to the
    # beginning correctly.
    p.stroke_mode(2.0, color='black')
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)
    p.turn_left(90)
    p.line_forward(5)
    p.turn_left(90)
    p.stroke_mode(2.0, color='red')
    p.line_forward(5)

    assert_equal(len(p.paper.paths), 1)

    assert_path_data(
        p, 0,
        [
            'M1,-1 L-1,1 L6,1 L6,-6 L-1,-6 L1,-4 L4,-4 L4,-1 L1,-1 z',
            'M1,-4 L-1,-6 L-1,1 L1,-1 L1,-4 z',
        ]
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:29,代码来源:test_pen.py

示例7: test_circle_line_overlap

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_circle_line_overlap():
    # Draw a circle that is above one line but below the other line.
    p = Pen()

    p.stroke_mode(1.0, color=(1.0, 0.0, 0.0))
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(4)

    p.fill_mode(color=(0.0, 1.0, 0.0))
    p.move_to((2, 2))
    p.circle(2)

    p.stroke_mode(1.0, color=(0.0, 0.0, 1.0))
    p.move_to((0, 4))
    p.turn_to(0)
    p.line_forward(4)

    assert_equal(
        p.paper.svg_elements(1),
        [
            (
                '<path d="M0.0,-0.5 L0.0,0.5 L4.0,0.5 L4.0,-0.5 L0.0,-0.5 z" '
                'fill="#ff0000" />'
            ),
            (
                '<path d="M4.0,-2.0 A 2.0,2.0 0 0 0 0.0,-2.0 '
                'A 2.0,2.0 0 0 0 4.0,-2.0 z" fill="#00ff00" />'
            ),
            (
                '<path d="M0.0,-4.5 L0.0,-3.5 L4.0,-3.5 L4.0,-4.5 L0.0,-4.5 z" '
                'fill="#0000ff" />'
            ),
        ]
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:37,代码来源:test_pen.py

示例8: test_custom_cap

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_custom_cap():

    def circle_cap(pen, end):
        pen.arc_to(end)

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().end_cap = circle_cap
    assert_path_data(
        p, 0,
        'M0,-1 L0,1 L5,1 A 1,1 0 0 0 5,-1 L0,-1 z'
    )

    p = Pen()
    p.stroke_mode(2.0)
    p.move_to((0, 0))
    p.turn_to(0)
    p.line_forward(5)
    p.last_segment().start_cap = circle_cap
    assert_path_data(
        p, 0,
        'M0,-1 A 1,1 0 1 0 0,1 L5,1 L5,-1 L0,-1 z'
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:28,代码来源:test_segment.py

示例9: test_line_line_half_illegal_joint

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_line_line_half_illegal_joint():
    # The outside edge meets, but the inside is too short to meet.
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    p.line_forward(2)
    p.turn_left(165)
    p.line_forward(2)

    assert_path_data(
        p, 2,
        (
            'M0.00,-0.50 L0.00,0.50 L5.80,0.50 L0.20,-1.00 '
            'L-0.06,-0.03 L1.87,0.48 L2.00,-0.50 L0.00,-0.50 z'
        )
    )

    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    p.line_forward(2)
    p.turn_right(165)
    p.line_forward(2)

    assert_path_data(
        p, 2,
        (
            'M0.00,-0.50 L0.00,0.50 L2.00,0.50 L1.87,-0.48 '
            'L-0.06,0.03 L0.20,1.00 L5.80,-0.50 L0.00,-0.50 z'
        )
    )
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:37,代码来源:test_segment.py

示例10: test_circle_degenerate

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:10,代码来源:test_pen.py

示例11: test_arc_joint_numerical

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_arc_joint_numerical():
    # Sometimes arc joints can miss the mark if they have odd float numbers.
    p = Pen()
    p.stroke_mode(0.5)
    p.move_to((-26.685559703113075, 65.00539003547281))
    p.turn_to(202.85281173472714)
    p.arc_right(180, 1)
    # This shouldn't error:
    p.arc_right(50.443252846269075, center=(0.5, 0.5))
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:11,代码来源:test_pen.py

示例12: test_arc_sweep_bug

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:14,代码来源:test_pen.py

示例13: test_straight_joint

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:14,代码来源:test_pen.py

示例14: test_arc_zero

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
def test_arc_zero():
    p = Pen()
    p.stroke_mode(1.0)
    p.move_to((0, 0))
    p.turn_to(0)

    # Zero-angle and zero-radius arcs have zero length, so they are not added.
    p.arc_left(0, radius=1)
    assert_equal(p.paper.paths, [])

    p.arc_left(90, radius=0)
    assert_equal(p.paper.paths, [])
开发者ID:christian-oudard,项目名称:canoepaddle,代码行数:14,代码来源:test_pen.py

示例15: test_arc_pie_slice

# 需要导入模块: from canoepaddle.pen import Pen [as 别名]
# 或者: from canoepaddle.pen.Pen import stroke_mode [as 别名]
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,代码行数:15,代码来源:test_pen.py


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