本文整理汇总了Python中turtle.Turtle.write_svg方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.write_svg方法的具体用法?Python Turtle.write_svg怎么用?Python Turtle.write_svg使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.write_svg方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fractal_image
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import write_svg [as 别名]
def fractal_image(name, angle, seed, rules, iterations=5, color=True):
stack = []
curve = seed
for i in range(iterations):
replaced_curve = ""
for char in curve:
if char in rules.keys():
replaced_curve += rules[char]
else:
replaced_curve += char
curve = replaced_curve
if color:
name += "_color"
t = Turtle(name=name)
for idx, step in enumerate(curve):
if step in ("F", "G"):
if color:
hsv_color = ((idx + 1) / len(curve), 0.75, 0.75)
rgb_color = [int(255 * i) for i in colorsys.hsv_to_rgb(*hsv_color)]
t.forward(10, color="rgb(%d, %d, %d" % (rgb_color[0], rgb_color[1], rgb_color[2]))
else:
t.forward(10)
elif step == "f":
t.penup()
t.forward(10)
t.pendown()
elif step == "-":
t.left(angle)
elif step == "+":
t.right(angle)
elif step == "|":
t.left(180)
elif step == "[":
t.push()
elif step == "]":
t.pop()
t.write_svg()