本文整理汇总了Python中turtle.Turtle.goForward方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.goForward方法的具体用法?Python Turtle.goForward怎么用?Python Turtle.goForward使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.goForward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wraps
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import goForward [as 别名]
# of sides), wraps (an integer specifying a wrap count), and decay
# (a float specifying a decay factor). Draw to standard draw a spiral
# with those characteristics.
n = int(sys.argv[1])
wraps = int(sys.argv[2])
decay = float(sys.argv[3])
angle = 360.0 / n
step = math.sin(math.radians(angle/2.0))
turtle = Turtle(0.5, 0, angle/2.0)
stddraw.setPenRadius(0.0)
stddraw.clear(stddraw.LIGHT_GRAY)
for i in range(wraps * n):
step /= decay
turtle.goForward(step)
turtle.turnLeft(angle)
stddraw.show()
#-----------------------------------------------------------------------
# python spiral.py 3 1 1.0
# python spiral.py 3 10 1.2
# python spiral.py 1440 10 1.0004
# python spiral.py 1440 10 1.00004
示例2: int
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import goForward [as 别名]
#-----------------------------------------------------------------------
# drunk.py
#-----------------------------------------------------------------------
import sys
import stdrandom
import stddraw
from turtle import Turtle
#-----------------------------------------------------------------------
# Accept as command-line arguments an integer stepCount specifying a
# number of iterations, and a float stepSize specifying a step size.
# Create a Turtle object, and have it make stepCount random steps of
# size stepSize.
stepCount = int(sys.argv[1])
stepSize = float(sys.argv[2])
stddraw.setPenRadius(0.0)
stddraw.clear(stddraw.LIGHT_GRAY)
myTurtle = Turtle(0.5, 0.5, 0.0)
for i in range(stepCount):
myTurtle.turnLeft(360.0 * stdrandom.uniformFloat(0.0, 360.0))
myTurtle.goForward(stepSize)
stddraw.show(0.0)
stddraw.show()
#-----------------------------------------------------------------------
# python drunk.py 10000 .01