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


Python Turtle.setheading方法代码示例

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


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

示例1: add_turtle

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setheading [as 别名]
def add_turtle(name):
    t = Turtle()
    t.speed('fast')
    #t.penup()
    t.shape(turtle_shapes[len(turtles) % len(turtle_shapes)])
    turtles[name] = t
    t.setheading(90)  # Point up
    return t
开发者ID:dcbriccetti,项目名称:python-lessons,代码行数:10,代码来源:server.py

示例2: placeTurtle

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

示例3: Raptor

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setheading [as 别名]
class Raptor(object):
    def __init__(self, distance, color, speed):
        self.turtle = Turtle()
        self.speed = speed
        self.turtle.pencolor(color)

        self.turtle.penup()
        self.turtle.forward(distance)
        self.turtle.pendown()

    def move(self, target):
        angle = self.turtle.towards(target)
        self.turtle.setheading(angle)
        self.turtle.forward(self.speed)
开发者ID:ethanwhite,项目名称:assets,代码行数:16,代码来源:object-pursuit.py

示例4: Material

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import setheading [as 别名]
class Material(object):
    def __init__(self):
        self.gods_hand = Turtle()
        self.gods_hand.hideturtle()
        self.gods_hand.speed(0)
        
    def draw_line(self):
        self.gods_hand.penup()
        self.gods_hand.tracer(0, 0)
        self.gods_hand.goto(100, 100)
        self.gods_hand.pendown()
        self.gods_hand.fill(True)
        self.gods_hand.setheading(0)
        self.gods_hand.forward(50)
        self.gods_hand.setheading(90)
        self.gods_hand.forward(50)
        self.gods_hand.setheading(180)
        self.gods_hand.forward(50)
        self.gods_hand.setheading(270)
        self.gods_hand.forward(50)
        self.gods_hand.fill(False)
        self.gods_hand.penup()
        self.gods_hand.goto(120, 120)
        self.gods_hand.pendown()
        self.gods_hand.pencolor("Blue")
        self.gods_hand.fillcolor("Blue")
        self.gods_hand.fill(True)
        self.gods_hand.setheading(0)
        self.gods_hand.forward(10)
        self.gods_hand.setheading(90)
        self.gods_hand.forward(10)
        self.gods_hand.setheading(180)
        self.gods_hand.forward(10)
        self.gods_hand.setheading(270)
        self.gods_hand.forward(10)
        
        self.gods_hand.fill(False)
        self.gods_hand.penup()
        self.gods_hand.tracer(1, 1)
        
    def build_box(self, pos_x, pos_y, length_x, length_y, do_fill, color):
        pos_x, pos_y = coordinate_converter((pos_x, pos_y))
        
        self.gods_hand.tracer(0, 0)
        
        self.gods_hand.penup()
        self.gods_hand.goto(pos_x, pos_y)
        self.gods_hand.pendown()
        
        if do_fill:
            self.gods_hand.fill(True)
            
        self.gods_hand.color(color)
            
        for x in range(4, 0, -1):
            heading = x * 90
            self.gods_hand.setheading(heading)    
            self.gods_hand.forward(length_x)
        
        if do_fill:
            self.gods_hand.fill(False)
        
        self.gods_hand.tracer(1, 1)
                 
    def draw_human(self, pos_x, pos_y):
        self.gods_hand.tracer(0, 0)
        self.gods_hand.penup()
        self.gods_hand.goto(pos_x, pos_y)
        self.gods_hand.color("blue")
        self.gods_hand.shape("circle")
        self.gods_hand.shapesize(0, 0, 5)
        stampid = self.gods_hand.stamp()
        self.gods_hand.color("black")
        self.gods_hand.tracer(1, 1)
        return stampid
        
    def erase_human(self, stampid):
        self.gods_hand.clearstamp(stampid)
开发者ID:gorbyebrius,项目名称:utbildning,代码行数:80,代码来源:m2_world_emulator.py

示例5: MazeGraphics

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


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