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


Python Turtle.backward方法代码示例

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


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

示例1: maketree

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
def maketree():
    p = Turtle(shape="triangle", visible=False)
    p.setundobuffer(None)
    p.fillcolor("green")
    p.shapesize(0.4)
    p.speed(0)
    p.left(90)
    p.penup()
    p.backward(210)
    p.pendown()
    tree([p], 200, 65, 0.6375)
开发者ID:1c71,项目名称:Program-Practice,代码行数:13,代码来源:tdemo_rtree1.py

示例2: __init__

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
class TurtleGTX:
      def __init__(self, name = ''):
      	  from turtle import Turtle
      	  self.odometer = 0
      	  self.name = name
      	  self.turtle = Turtle()
      def forward(self, distance):
      	  try:
      	      if self.odometer > 1000:
      	         raise ValueError("Need to switch for a new tyre")
      	      if distance > 0:
		 self.odometer += distance
		 self.turtle.forward(distance)
	      if distance < 0:
	      	 self.odometer += distance*(-1)
		 self.turtle.backward(distance*(-1))
      	  except:
      	  	 print("Need to switch for a new tyre")
      def  change_tyre(self):
      	   self.odometer = 0 
开发者ID:karimov,项目名称:py-solved-tasks,代码行数:22,代码来源:turtlegtx.py

示例3: random_color

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
from turtle import Turtle
from random import random

def random_color():
    return (random(),random(),random())


artist = Turtle()
artist.penup()
artist.pensize(400)
artist.speed(7)
artist.hideturtle()
artist.backward(200)
artist.left(90)
artist.forward(200)
artist.right(90)
artist.pendown()

while True:
    for count in range(4):
        artist.pencolor(random_color())
        artist.forward(500)
        artist.right(90)

input()
开发者ID:ameerkazamhamed,项目名称:python-tutorials,代码行数:27,代码来源:square1.py

示例4: Turtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
from turtle import Turtle, mainloop

raptor = Turtle()
raptor.pencolor("red")
raptor.backward(200)

duckbill = Turtle()
duckbill.pencolor("green")
duckbill.forward(200)

mainloop()
开发者ID:LJWilliams,项目名称:assets,代码行数:13,代码来源:position-dinosaurs.py

示例5: ParsonTurtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [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: snowflake

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
from turtle import Turtle, Screen


def snowflake(t, iterations, size):
    if iterations == 0:  # Base Case
        t.forward(size)
    else:
        pass


atuin = Turtle()
window = Screen()

atuin.color("#FFFFFF")
window.bgcolor("#0191C8")

atuin.penup()
atuin.backward(50)
atuin.pendown()
atuin.pensize(4)

num_sides = 3
iterations = 0

for i in range(num_sides):
    snowflake(atuin, iterations, 100)
    atuin.right(360 / num_sides)

window.exitonclick()
开发者ID:WheatonWHALE,项目名称:comp115,代码行数:31,代码来源:15_snowflake.py

示例7: random_color

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
from turtle import Turtle
from random import random

def random_color():
    return(random(),random(),random())

MorganFreeman = Turtle()
MorganFreeman.pensize(9)
MorganFreeman.speed(0)

while True:
    for counter in range(50):
        MorganFreeman.pencolor(random_color())
        MorganFreeman.forward(counter)
        MorganFreeman.backward(counter+25)
        MorganFreeman.right(25)
    MorganFreeman.penup()
    MorganFreeman.right(90)
    MorganFreeman.forward(50)
    MorganFreeman.pendown()
    for counter in range(50):
        MorganFreeman.pencolor(random_color())
        MorganFreeman.forward(counter)
        MorganFreeman.backward(counter+25)
        MorganFreeman.left(25)


        
    
    
    
开发者ID:donovank,项目名称:python-2,代码行数:27,代码来源:Loading.py

示例8: random_color

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
from turtle import Turtle
from random import random

def random_color():
    return(random(),random(),random())

nibles = Turtle()
nibles.pensize(7)
nibles.speed(0)
for counter in range(1,200):
    nibles.pencolor(random_color())
    nibles.right(10)
    nibles.left(20)
    nibles.backward(1)
    nibles.forward(10)
    nibles.
    
开发者ID:baconrider46,项目名称:python-projects,代码行数:18,代码来源:loading.py

示例9: Screen

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
            games. Bear in mind that the simplicity of the turtle library hurts its performance
             considerabily. Therefore is is seen as a stepping stone to other more powerful low-level
              libraries such as openGl, Vulkan and DirectX12
    -------------------------------------- Jonas -------------------- """

from turtle import Turtle, Screen

# --- Create objects---
screen = Screen()
tut1 = Turtle()
tut2 = Turtle()

# --- INIT turtles ---
tut1.speed(1)
tut1.penup()
tut1.shape("circle")
tut1.shapesize(5)
tut1.color("red")

tut2.speed(1)
tut2.penup()
tut2.shape("square")
tut2.shapesize(5)
tut2.color("blue")

# --- ACTION ---
tut1.forward(100)
tut2.backward(100)

screen.mainloop()
开发者ID:kenrem6,项目名称:pythonNoob,代码行数:32,代码来源:turtleGame1.py

示例10: MazeGraphics

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [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

示例11:

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [as 别名]
cursor.forward(100)
cursor.right(135)
cursor.forward(140)
cursor.left(135)
cursor.forward(100)
time.sleep(0.5)
cursor.clear()
 
 
cursor.penup()
cursor.setposition(-70,0)
cursor.color('black')
cursor.pendown()
cursor.right(90)
cursor.forward(100)
cursor.backward(50)
cursor.left(90)
cursor.forward(100)
cursor.left(90)
cursor.forward(50)
cursor.backward(100)
time.sleep(0.5)
cursor.clear()
 
cursor.penup()
cursor.right(180)
cursor.setposition(-300,0)
 
cursor.color('red')
cursor.pendown()
cursor.left(90)
开发者ID:mani1996,项目名称:Remember-My-Name,代码行数:33,代码来源:script.py

示例12: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import backward [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.backward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。