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


Python Pen.parametric方法代碼示例

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


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

示例1: draw

# 需要導入模塊: from canoepaddle import Pen [as 別名]
# 或者: from canoepaddle.Pen import parametric [as 別名]
def draw():

    p = Pen()

    # Draw sine waves in various widths.
    for width in [0.01, 0.1, 0.3, 0.5, 0.8, 1.0]:
        p.stroke_mode(width)

        func = sine_func_factory(
            amplitude=1.0,
            frequency=4 / math.pi,
            phase=0,
        )
        p.parametric(
            func,
            start=0,
            end=10,
            step=0.1,
        )
        # Next line.
        p.turn_to(-90)
        p.move_forward(1.0 + 2 * width)

    return p.paper
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:26,代碼來源:sine.py

示例2: draw

# 需要導入模塊: from canoepaddle import Pen [as 別名]
# 或者: from canoepaddle.Pen import parametric [as 別名]
def draw():

    p = Pen()

    center_radius = 3.0
    start_radius = radius = 100
    start_width = width = 3.0
    ratio = (1 / 2) ** (1/5)


    series = []
    while radius > center_radius / sqrt2:
        series.append((radius, width))
        radius *= ratio
        width *= ratio

    p.move_to((0, 0))
    for radius, width in series:
        p.stroke_mode(width, 'black')
        p.circle(radius)

    # Parametric conic spirals.
    p.move_to((0, 0))

    def spiral(theta):
        b = (1 / 2) ** (-2 / math.pi)
        r = start_radius * (b ** (-theta))
        x = r * math.cos(theta)
        y = r * math.sin(theta)
        z = start_radius - r
        return (x, y, z)

    def spiral_top1(t):
        x, y, z = spiral(t)
        return x, y

    def spiral_top2(t):
        x, y, z = spiral(t)
        x = -x
        y = -y
        return x, y

    # Top spirals.
    p.stroke_mode(start_width, 'black')
    p.parametric(spiral_top1, 0, 4*math.pi, .1)
    p.parametric(spiral_top2, 0, 4*math.pi, .1)

    # Blank out the bottom triangle.
    p.fill_mode('white')
    p.move_to((0, 0))
    s = start_radius + start_width
    p.line_to((-s, -s))
    p.line_to((+s, -s))
    p.line_to((0, 0))

    # Horizontal lines for the bottom triangle.
    for radius, width in series:
        p.stroke_mode(width, 'black')
        p.move_to((-radius, -radius))
        p.line_to(
            (+radius, -radius),
            start_slant=45,
            end_slant=-45,
        )

    # Front spirals.
    def spiral_front1(t):
        x, y, z = spiral(t)
        return (x, z - start_radius)

    def spiral_front2(t):
        x, y, z = spiral(t)
        x = -x
        y = -y
        return (x, z - start_radius)

    p.move_to((0, 0))
    p.stroke_mode(start_width, 'black')
    p.parametric(spiral_front1, 0, math.pi, .1)
    p.parametric(spiral_front2, math.pi, 2*math.pi, .1)
    p.parametric(spiral_front1, 2*math.pi, 3*math.pi, .1)

    # Fill in the center.
    p.move_to((0, 0))
    p.fill_mode('black')
    p.circle(center_radius)

    return p.paper
開發者ID:christian-oudard,項目名稱:canoepaddle,代碼行數:90,代碼來源:mountain.py


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