本文整理汇总了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
示例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