本文整理汇总了Python中turtle.Turtle.setposition方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.setposition方法的具体用法?Python Turtle.setposition怎么用?Python Turtle.setposition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.setposition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Turtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [as 别名]
from time import sleep
from turtle import Turtle
x , y = 80 , 80
x_top, y_top = -x//2, y//2
moteur = Turtle()
moteur.setposition(x_top, y_top)
for y0 in range(y_top, -y_top, -1):
if((-1)*((-1)**(y0%2)) == 1):
for x0 in range(x_top, -x_top, 1):
moteur.setposition(x0, y0)
else:
for x0 in range(-x_top, x_top, -1):
moteur.setposition(x0, y0)
sleep(20)
示例2: ParsonTurtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [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:
#.........这里部分代码省略.........
示例3: Turtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [as 别名]
for char in self[index]:
if char in self.actions:
self.update()
self.actions[char]()
if __name__=='__main__':
import sys
from turtle import Turtle
turtle = Turtle()
turtle.hideturtle()
turtle.speed('fastest')
turtle.screen.colormode(255)
turtle.up()
turtle.setposition(-200, 200)
turtle.down()
fractals = {
'snowflake': L_System(turtle, 'F++F++F', {'F': 'F-F++F-F'}, 60),
'dragon': L_System(turtle, 'FX', {'X': 'X+YF', 'Y': 'FX-Y'}, 90),
'plant': L_System(turtle, 'FX', {'X': 'F-[[X]+X]+F[+FX]-X', 'F': 'FF'}, 25),
'sierpinsky': L_System(turtle, 'FA', {'FA': 'FB-FA-FB', 'FB': 'FA+FB+FA'}, 60),
'koch':L_System(turtle,'F',{'F':'F+F-F-F+F'},90)
}
name,num = sys.argv[1], int(sys.argv[2])
fractals[name].draw(num)
turtle.screen.exitonclick()
示例4: Drawing
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [as 别名]
class Drawing():
def __init__(self):
"""
This drawing class is for practicing drawing simple or even geometrical
pictures with turtle module.
Let's apply this method with easy examples.
gb = turtle.Turtle() ; gb.rigth, left, forward, backward, circle, shape,
shapesize, penup, pendown, home, clear
You can get a lot of detail information by googling 'python turtle'.
"""
self.gb = Turtle()
self.gb.shape('turtle')
self.gb.speed(6)
#self.screen = self.gb.getscreen()
#w = 150
#self.screen.setworldcoordinates(-w,-w,w,w)
print 'A cute turtle is ready to draw!'
def swirl(self,shape='turtle',speed=0):
self.gb.shape(shape)
self.gb.speed(speed)
self.gb.color('black')
for i in range(500):
self.gb.forward(i)
self.gb.right(98)
def color_swirl(self,shape='turtle',speed=0):
self.gb.shape(shape)
self.gb.speed(speed)
for i in range(500):
color = colorsys.hsv_to_rgb(i/1000.0,1.0,1.0)
self.gb.color(color)
self.gb.forward(i)
self.gb.right(98)
def zigzag(self,shape='turtle',speed=0):
self.gb.shape(shape)
self.gb.speed(speed)
for i in range(180):
self.gb.forward(100)
self.gb.right(30)
self.gb.forward(20)
self.gb.left(60)
self.gb.forward(50)
self.gb.right(30)
self.gb.penup()
self.gb.setposition(0,0)
self.gb.pendown()
self.gb.right(2)
def square(self,shape='turtle',speed=0):
self.gb.shape(shape)
self.gb.speed(speed)
for i in range(400):
self.gb.forward(i)
self.gb.left(90.5)
def gohome(self):
wiggle = [30,30,30,30]
self.gb.shape('turtle')
self.gb.speed(6)
self.gb.clear()
self.gb.penup()
for tick in wiggle:
self.gb.right(tick)
self.gb.left(tick)
self.gb.home()
self.gb.clear()
self.gb.pendown()
self.gb.color('black')
示例5: MazeGraphics
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [as 别名]
class MazeGraphics(object):
def __init__(self, config):
self.width = config.getValueAsInt("maze", "maze_size")
self.height = config.getValueAsInt("maze", "maze_size")
self.bg_color = config.getValue("maze", "bg_color")
self.line_color = config.getValue("maze", "line_color")
self.line_centroid_color = config.getValue("maze", "line_centroid_color")
self.forward_centroid_color = config.getValue("maze", "forward_centroid_color")
self.reverse_centroid_color = config.getValue("maze", "reverse_centroid_color")
self.path_color = config.getValue("maze", "path_color")
self.screen = Screen()
self.setupTurtle(self.width, self.height)
def setupTurtle(self, width, height):
self.screen.tracer(False)
self.screen.screensize(width, height)
# some basic turtle settings
self.screen.setworldcoordinates(-1, -1, width + 1, height + 1)
self.screen.title("Random Turtle Maze")
self.screen.bgcolor(self.bg_color)
self.screen.delay(None)
self.designer = Turtle(visible=False)
def drawGrid(self):
for i in xrange(0, self.width + 1):
self.drawXLines(i, self.width, self.line_color)
for i in xrange(0, self.height + 1):
self.drawYLines(i, self.width, self.line_color)
self.screen.update()
def drawXLines(self, position, width, color):
self.drawLines(position, 0, width, color, 90)
def drawYLines(self, position, width, color):
self.drawLines(0, position, width, color, 0)
def drawLines(self, xPosition, yPosition, width, color, heading):
self.designer.up()
self.designer.setposition(xPosition, yPosition)
self.designer.color(color)
self.designer.down()
self.designer.setheading(heading)
self.designer.forward(width)
self.designer.up()
def drawCentroid(self, cell, color):
"""
Draw a centroid for animation purposes but then overwrite it.
"""
self.designer.setposition(cell.centroid)
self.designer.dot(5, color)
self.screen.update()
self.designer.dot(5, self.bg_color)
def removeWall(self, posx, posy, heading, color):
"""
We tear down walls to build the maze
"""
self.designer.up()
self.designer.setposition(posx, posy)
self.designer.down()
self.designer.color(color)
self.designer.setheading(heading)
self.designer.forward(1)
self.designer.up()
self.screen.update()
def drawPath(self, cell1, cell2):
"""
This draws a line for the solution as it's worked out.
"""
self.designer.setposition(cell1.centroid)
self.designer.color(self.path_color)
direction = self.getDirection(cell1, cell2)
if direction == "N":
self.designer.setheading(90)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "S":
self.designer.setheading(270)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "W":
self.designer.setheading(0)
self.designer.down()
self.designer.forward(1)
self.designer.up()
elif direction == "E":
self.designer.setheading(0)
self.designer.down()
self.designer.backward(1)
self.designer.up()
self.drawCentroid(cell2, self.line_centroid_color)
self.screen.update()
def getDirection(self, currCell, nextCell):
direction = None
if nextCell.x < currCell.x:
#.........这里部分代码省略.........
示例6: Turtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setposition [as 别名]
#!/usr/bin/python
import turtle,time
from turtle import Turtle
cursor = Turtle()
cursor.speed(2)
cursor.penup()
cursor.setposition(-70,0)
cursor.color('red')
cursor.pendown()
cursor.left(90)
cursor.forward(100)
cursor.right(150)
cursor.forward(115)
cursor.left(120)
cursor.forward(115)
cursor.right(150)
cursor.forward(100)
time.sleep(0.5)
cursor.clear()
cursor.penup()
cursor.setposition(-70,0)
cursor.right(180)
cursor.color('blue')
cursor.pendown()
cursor.right(30)
cursor.forward(115)
cursor.right(120)
cursor.forward(115)