当前位置: 首页>>代码示例>>Python>>正文


Python Turtle.up方法代码示例

本文整理汇总了Python中turtle.Turtle.up方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.up方法的具体用法?Python Turtle.up怎么用?Python Turtle.up使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在turtle.Turtle的用法示例。


在下文中一共展示了Turtle.up方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
def main(configuration):
    t = Turtle()
    t.speed(10)
    t.up()
    t.setpos(-configuration['size']/2,-configuration['size']/2)
    colormode(255)
    sierpinski(t,configuration['level'],configuration['size'])
开发者ID:tmmgarcia,项目名称:uwa-2014-cits1401-sierpinski,代码行数:9,代码来源:runner.py

示例2: startTurtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
def startTurtle():
    t = Turtle()
    t.speed(10)
    t.up()
    t.setpos(-dim/2,-dim/2)
    colormode(255)
    return t
开发者ID:tmmgarcia,项目名称:uwa-2014-cits1401-2,代码行数:9,代码来源:drawBoard.py

示例3: placeTurtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
 def placeTurtle(self,x,y):
     newT = Turtle()
     newTscreen = newT.getscreen()
     newTscreen.tracer(0)
     newT.up()
     newT.goto(x,y)
     newT.shape('turtle')
     newT.setheading(random.randint(1,359))
     newTscreen.tracer(1)
     self.numTurtles = self.numTurtles + 1
     self.turtleList.append(newT)
     if self.numTurtles >= self.maxTurtles:
         self.bigTscreen.onclick(None)
开发者ID:azmikamis,项目名称:pythonworks,代码行数:15,代码来源:turtleplace.py

示例4: __init__

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
class TurtlePlace:
    def __init__(self,maxTurtles,hWall=200,vWall=200):
        self.bigT = Turtle()
        self.bigTscreen = self.bigT.getscreen()
        self.bigT.shape('turtle')
        self.turtleList = []
        self.bigTscreen.onclick(self.placeTurtle)
        self.bigT.hideturtle()
        self.numTurtles = 0
        self.maxTurtles = maxTurtles
        self.hWall = hWall
        self.vWall = vWall
        self.drawField(hWall,vWall)
        mainloop()

    def placeTurtle(self,x,y):
        newT = AnimatedTurtle(self.hWall,self.vWall)
        newTscreen = newT.getscreen()
        newTscreen.tracer(0)
        newT.up()
        newT.goto(x,y)
        newT.shape('turtle')
        newT.setheading(random.randint(1,359))
        newTscreen.tracer(1)
        self.numTurtles = self.numTurtles + 1
        self.turtleList.append(newT)
        if self.numTurtles >= self.maxTurtles:
            self.bigTscreen.onclick(None)

    def drawField(self,hWall,vWall):
        self.bigTscreen.tracer(0)
        self.bigT.up()
        self.bigT.goto(-hWall,-vWall)
        self.bigT.down()
        for i in range(4):
            self.bigT.forward(2*hWall)
            self.bigT.left(90)
        self.bigTscreen.tracer(1)
开发者ID:azmikamis,项目名称:pythonworks,代码行数:40,代码来源:bouncingturtles.py

示例5: ParsonTurtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [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:
#.........这里部分代码省略.........
开发者ID:vkaravir,项目名称:skulpt,代码行数:103,代码来源:__init__.py

示例6: Turtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
        self.size = size
        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()
开发者ID:zarthon,项目名称:lSystems,代码行数:33,代码来源:L_SystemImplementation.py

示例7: __init__

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
class KeysMouseEvents:
	def __init__(self):
		super().__init__()
		self.reinit()

	def reinit(self):
		self.T=Turtle()
		self.screen=self.T.getscreen()
		self.screen.onclick(self.drawcir)
		self.screen.onkey(self.clear,"c")
		self.T.pensize(5)
		self.screen.listen()
		self.count=0
		self.firstx=0
		self.firsty=0
		self.secondx=0
		self.secondy=0
		self.T.hideturtle()
		self.T.up()

	def clear(self):
		self.T.screen.clear()
		self.reinit()

		
	def drawcir(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			self.T.color("black")
			self.firstx=x
			self.firsty=y
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.T.up()
			return
		if self.count == 2:
			self.secondx=x
			self.secondy=y
			X = self.secondx - self.firstx
			Y = self.secondy - self.firsty
			d = X * X + Y * Y

			self.T.color("black")
			radious = math.sqrt (d);
			self.T.goto(self.firstx, self.firsty-radious)
			self.T.down()
			self.T.circle(radious)
			self.T.up()


			c = random.randint(1, 4)
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")

			self.T.begin_fill()
			radious=radious-4
			self.T.goto(self.firstx, self.firsty-radious)
			self.T.down()
			self.T.circle(radious)
			self.T.end_fill()
			self.T.up()

			self.T.color("black")
			self.T.goto(self.firstx,self.firsty)
			self.T.down()
			self.T.dot()
			self.T.up()

			self.count=0
	def main(self):
		mainloop()
开发者ID:srutak,项目名称:srutak.github.io,代码行数:80,代码来源:pydraw.py

示例8: MazeGraphics

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [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:
#.........这里部分代码省略.........
开发者ID:skroah,项目名称:pythonmaze,代码行数:103,代码来源:mazegraphics.py

示例9: sorted

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
# Pro zajímavost, jiný styl vykreslení :)
# maze = sorted(set(generate_maze(start=start_point)))


#Vykreslí posunutou šedou a pak bílou, 3d efekt
for (start, end) in maze:
    offset = 0.5,0.5
    draw_line(t, add_point(start,offset),
                 add_point(end,offset),
                 color="black", size=DISTANCE//2)
for (start, end) in maze:
    draw_line(t, start, end,
              color="gray", size=DISTANCE//2)
#Označí začátek a start    
for point in (start_point, end_point):
    t.up()
    t.goto(*point)
    t.down()
    t.dot("red")


# A pokud se nám chce, najdeme si cestu.    
g = create_graph_of_maze(maze)
p = find_path(start_point, end_point, graph=g)
for start,end in zip(p[:-1], p[1:]):
    draw_line(t, start, end, color="red", size=3)

# Ukončení vykreslení želvy, pokud řádek chybí
# bůhví proč nevykreslí poslední hranu cesty.
# Nejspíš souvisí s nastavením traceru
t.up()
开发者ID:a1ip,项目名称:my_check,代码行数:33,代码来源:main.py

示例10: __init__

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
class KeysMouseEvents:
	def __init__(self):
		super().__init__()
		self.reinit()

	def reinit(self):
		self.T=Turtle()
		self.screen=self.T.getscreen()
		self.screen.onclick(self.drawcir)
		self.screen.onkey(self.clear,"c")
		self.T.pensize(5)
		self.screen.listen()
		self.count=0
		self.firstx=0
		self.firsty=0
		self.secondx=0
		self.secondy=0
		self.T.hideturtle()
		self.T.up()

	def clear(self):
		self.T.screen.clear()
		self.reinit()

	def drawcir(self,x,y):
		self.count = (self.count + 1) 
		if self.count == 1:
			self.T.color("black")
			self.firstx=x
			self.firsty=y
			self.T.goto(x,y)
			self.T.down()
			self.T.dot()
			self.T.up()
			return
		if self.count == 2:
			self.secondx=x
			self.secondy=y
			X = self.secondx - self.firstx
			Y = self.secondy - self.firsty
			d = X * X + Y * Y
			
			self.T.color("black")
			
			radius = math.sqrt (d);
			len = math.sqrt (2*radius*radius)
			a = len/2
			b = math.sqrt((radius*radius)-(a*a))
			self.T.goto(self.firstx-radius, self.firsty+radius)
			self.T.down()
			width = 2*radius
			height = 2*radius
			self.T.speed(0)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.up()

			x = random.randint(1, 7)
			c = x
			if c == 1:
				self.T.color("red")
			if c == 2:
				self.T.color("green")
			if c == 3:
				self.T.color("blue")
			if c == 4:
				self.T.color("yellow")
			if c == 5:
				self.T.color("white")
			if c == 6:
				self.T.color("pink")
			if c == 7:
				self.T.color("brown")
			if c == 8:
				self.T.color("purple")
			if c == 9:
				self.T.color("gray")
			if c == 10:
				self.T.color("orange")
			self.T.begin_fill()
			radius1=radius-4
			self.T.goto(self.firstx-radius1, self.firsty+radius1)
			self.T.down()
			width = 2*radius1
			height = 2*radius1
			self.T.speed(0)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
			self.T.forward(width)
			self.T.right(90)
			self.T.forward(height)
			self.T.right(90)
#.........这里部分代码省略.........
开发者ID:srutak,项目名称:srutak.github.io,代码行数:103,代码来源:pydraw.py

示例11: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import up [as 别名]
def main():
    t = Turtle()
    my_win = Screen()
    t.width(12)
    t.speed(10)
    t.left(90)
    t.up()
    t.backward(100)
    t.down()
    t.color("brown")
    tree(75, t)
    my_win.exitonclick()
开发者ID:praetore,项目名称:python-data-structures-and-algorithms,代码行数:14,代码来源:turtletree.py


注:本文中的turtle.Turtle.up方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。