本文整理汇总了Python中turtle.Turtle.setx方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.setx方法的具体用法?Python Turtle.setx怎么用?Python Turtle.setx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.setx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Turtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setx [as 别名]
from turtle import Turtle
t = Turtle()
t.setx(-200)
for step in range(36):
t.forward(400)
t.right(170)
t.done()
示例2: main
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setx [as 别名]
def main():
side = float(input('Enter a side length: '))
turtle = Turtle()
turtle.penup()
turtle.setx(-side / 2)
turtle.sety(side / 2)
turtle.pendown()
turtle.speed('slowest')
turtle.color('green')
turtle.pensize(5)
for i in range(4):
turtle.forward(side)
turtle.right(90)
done()
示例3: drawgrid
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setx [as 别名]
def drawgrid(size):
myturtle = Turtle()
mysreen = myturtle.getscreen()
mysreen.setworldcoordinates(-1, -1, size + 1, size + 1)
myturtle.setx(0)
myturtle.sety(0)
for i in range(size - 1):
myturtle.forward(size - 1)
myturtle.sety(i + 1)
myturtle.setx(0)
myturtle.setx(0)
myturtle.sety(0)
myturtle.left(90)
for i in range(size - 1):
myturtle.forward(size - 1)
myturtle.setx(i + 1)
myturtle.sety(0)
return myturtle, mysreen
示例4: ParsonTurtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setx [as 别名]
class ParsonTurtle(Turtle):
def __init__(self):
self._turtle = Turtle()
self._turtle.shape('turtle')
self._commands = []
def forward(self, dist, log=True):
self._turtle.forward(dist)
if log:
self._commands.append("fwd" + str(dist))
def fd(self, dist, log=True):
return self.forward(dist, log=log)
def backward(self, dist, log=True):
self._turtle.backward(dist)
if log:
self._commands.append("bwd" + str(dist))
def back(self, dist, log=True):
return self.backward(dist, log=log)
def bk(self, dist, log=True):
return self.backward(dist, log=log)
def left(self, angle, log=True):
self._turtle.left(angle)
if log:
self._commands.append("lt" + str(angle))
def lt(self, angle, log=True):
return self.left(angle, log=log)
def right(self, angle, log=True):
self._turtle.right(angle)
if log:
self._commands.append("rt" + str(angle))
def rt(self, angle, log=True):
return self.right(angle, log=log)
def goto(self, nx, ny, log=True):
self._turtle.goto(nx, ny)
if log:
self._commands.append("gt" + str(nx) + "-" + str(ny))
def setposition(self, nx, ny, log=True):
self._turtle.setposition(nx, ny)
if log:
self._commands.append("setpos" + str(nx) + "-" + str(ny))
def setpos(self, nx, ny, log=True):
return self.setposition(nx, ny, log=log)
def setx(self, nx, log=True):
self._turtle.setx(nx)
if log:
self._commands.append("setx" + str(nx))
def sety(self, ny, log=True):
self._turtle.sety(ny)
if log:
self._commands.append("sety" + str(ny))
def dot(self, size, color, log=True):
self._turtle.dot(size, color)
if log:
self._commands.append("dot" + str(size) + "-" + str(color))
def circle(self, radius, extent, log=True):
self._turtle.circle(radius, extent)
if log:
self._commands.append("circle" + str(radius) + "-" + str(extent))
def up(self, log=True):
self._turtle.up()
if log:
self._commands.append("up")
def penup(self, log=True):
return self.up(log=log)
def pu(self, log=True):
return self.up(log=log)
def down(self, log=True):
self._turtle.down()
if log:
self._commands.append("down")
def pendown(self, log=True):
return self.down(log=log)
def pd(self, log=True):
return self.down(log=log)
def speed(self, spd):
self._turtle.speed(spd)
def _logColorChange(self, command, color, green, blue):
if blue is not None:
self._commands.append("%s(%d, %d, %d)"%(command, color, green, blue))
else:
self._commands.append("%s(%s)"%(command, color))
def pencolor(self, color, green=None, blue=None, log=True):
if blue is not None:
self._turtle.pencolor(color, green, blue)
else:
#.........这里部分代码省略.........