python类Turtle()的实例源码

maze.py 文件源码 项目:Python-PACMEZ 作者: alibolek 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(self):
        turtle.Turtle.__init__(self)  # first initialize MazeTurtle as a Turtle
        self.penup()
        self.shape("turtle")
        # new properties specific to MazeTurtles
        self.cell = Cell(0,0)
        self.dir = STAND
        self.score = 0
        self.lives = 3
tk.py 文件源码 项目:transpyler 作者: Transpyler 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, *args, **kwargs):
        from turtle import Turtle

        self.turtle = Turtle()
        super().__init__(*args, **kwargs)
tk.py 文件源码 项目:transpyler 作者: Transpyler 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def make_turtle_namespace():
    """
    Returns a dictionary with the namespace of turtle functions.
    """

    return dict(TurtleNamespace(Turtle))
spgl.py 文件源码 项目:SPGL 作者: wynand1004 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __init__(
                self,
                screen_width = 800,
                screen_height = 600,
                background_color = "black",
                title = "Simple Game Library by /u/wynand1004 AKA @TokyoEdTech",
                splash_time = 3):

        # Setup using Turtle module methods
        turtle.setup(width=screen_width, height=screen_height)
        turtle.bgcolor(background_color)
        turtle.title(title)
        turtle.tracer(0) # Stop automatic screen refresh
        turtle.listen() # Listen for keyboard input
        turtle.hideturtle() # Hides default turtle
        turtle.penup() # Puts pen up for defaut turtle
        turtle.setundobuffer(0) # Do not keep turtle history in memory
        turtle.onscreenclick(self.click)

        # Game Attributes
        self.FPS = 30.0 # Lower this on slower computers or with large number of sprites
        self.SCREEN_WIDTH = screen_width
        self.SCREEN_HEIGHT = screen_height
        self.DATAFILE = "game.dat"
        self.SPLASHFILE = "splash.gif" # Must be in the same folder as game file

        self.title = title
        self.gravity = 0
        self.state = "showsplash"
        self.splash_time = splash_time

        self.time = time.time()

        # Clear the terminal and print the game title
        self.clear_terminal_screen()
        print (self.title)

        # Show splash
        self.show_splash(self.splash_time)

    # Pop ups
spgl.py 文件源码 项目:SPGL 作者: wynand1004 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self,
                shape,
                color,
                x = 0,
                y = 0):

        turtle.Turtle.__init__(self)
        # self.hideturtle()
        self.penup()
        # Register shape if it is a .gif file
        if shape.endswith(".gif"):
            try:
                turtle.register_shape(shape)
            except:
                Game.logs.append("Warning: {} file missing from disk.".format(shape))

                # Set placeholder shape
                shape = "square"

        self.shape(shape)
        self.color(color)
        self.goto(x, y)

        #Set click binding
        self.onclick(self.click)

        # Append to master button list
        Game.buttons.append(self)
spgl.py 文件源码 项目:SPGL 作者: wynand1004 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def __init__(
                self,
                screen_width = 800,
                screen_height = 600,
                background_color = "black",
                title = "Simple Game Library by /u/wynand1004 AKA @TokyoEdTech",
                splash_time = 3):

        # Setup using Turtle module methods
        turtle.setup(width=screen_width, height=screen_height)
        turtle.bgcolor(background_color)
        turtle.title(title)
        turtle.tracer(0) # Stop automatic screen refresh
        turtle.listen() # Listen for keyboard input
        turtle.hideturtle() # Hides default turtle
        turtle.penup() # Puts pen up for defaut turtle
        turtle.setundobuffer(0) # Do not keep turtle history in memory
        turtle.onscreenclick(self.click)

        # Game Attributes
        self.FPS = 30.0 # Lower this on slower computers or with large number of sprites
        self.SCREEN_WIDTH = screen_width
        self.SCREEN_HEIGHT = screen_height
        self.DATAFILE = "game.dat"
        self.SPLASHFILE = "splash.gif" # Must be in the same folder as game file

        self.title = title
        self.gravity = 0
        self.state = "showsplash"
        self.splash_time = splash_time

        self.time = time.time()

        # Clear the terminal and print the game title
        self.clear_terminal_screen()
        print (self.title)

        # Show splash
        self.show_splash(self.splash_time)

    # Pop ups
spgl.py 文件源码 项目:SPGL 作者: wynand1004 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__(self,
                shape,
                color,
                x = 0,
                y = 0):

        turtle.Turtle.__init__(self)
        # self.hideturtle()
        self.penup()
        # Register shape if it is a .gif file
        if shape.endswith(".gif"):
            try:
                turtle.register_shape(shape)
            except:
                Game.logs.append("Warning: {} file missing from disk.".format(shape))

                # Set placeholder shape
                shape = "square"

        self.shape(shape)
        self.color(color)
        self.goto(x, y)

        #Set click binding
        self.onclick(self.click)

        # Append to master button list
        Game.buttons.append(self)
TP2-CH4-Exercises.py 文件源码 项目:IntroPython2016 作者: UWPCE-PythonCert 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def draw_circle_with_square():
    purple_turtle = turtle.Turtle()
    purple_turtle.shape("circle")
    purple_turtle.speed(9)
    purple_turtle.pensize(3)
    purple_turtle.hideturtle()
    for i in range(1,37):
        if i % 2 == 0:
            purple_turtle.color("white")
        else:
            purple_turtle.color("#732C7B")
        draw_square(purple_turtle)
        purple_turtle.right(10)

#def draw_circle():
#   turtle_two = turtle.Turtle()
#   turtle_two.shape("arrow")
#   turtle_two.color("white")
#   turtle_two.circle(100)
#   
#def draw_triangle():
#   turtle_three = turtle.Turtle()
#   turtle_three.shape("turtle")
#   turtle_three.color("black")
#   turtle_three.backward(100)
#   turtle_three.left(60)
#   turtle_three.forward(100)
#   turtle_three.right(120)
#   turtle_three.forward(100)
Turtle_Mini_Project_KC.py 文件源码 项目:Python-first-Practice 作者: MurphyWan 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def Turtle_Mini_Project_KC():
    window = turtle.Screen()
    window.bgcolor("white")
    brad = turtle.Turtle()
    brad.shape("turtle")
    brad.color("blue")
    brad.speed(1)

    draw_K(brad)
    draw_C(brad)

    window.exitonclick()
day17-homework.py 文件源码 项目:uband-python-s1-july 作者: guoylyy 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def main():
  #??????
  windows = turtle.Screen()
  #????
  windows.bgcolor('blue')
  #????????
  bran = turtle.Turtle()
  bran.shape('turtle')
  bran.color('yellow')
  #??????
  for i in range(1,3):
    bran.setposition(300,300)
    bran.setheading(90)
    bran.setposition(300,0)
    bran.setheading(90)
    bran.setposition(0,0)
    bran.setheading(90)

    bran.dot(60,'red')

  bran.color('black')
  bran.stamp()
  bran.forward(-300)
  bran.right(90)
  bran.forward(300)
  bran.left(90)
  bran.forward(300)

  bran.clearstamps()

  for i in range(5):
    bran.undo()
day17-homework.py 文件源码 项目:uband-python-s1-july 作者: guoylyy 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def main():
  #??????
  windows = turtle.Screen()
  #????
  windows.bgcolor('blue')
  #????????
  bran = turtle.Turtle()
  bran.shape('turtle')
  bran.color('yellow')
  #??????
nim.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, row, col, game):
        turtle.Turtle.__init__(self, visible=False)
        self.row = row
        self.col = col
        self.game = game
        x, y = self.coords(row, col)
        self.shape("square")
        self.shapesize(HUNIT/10.0, WUNIT/20.0)
        self.speed(0)
        self.pu()
        self.goto(x,y)
        self.color("white")
        self.showturtle()
tree.py 文件源码 项目:zippy 作者: securesystemslab 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def maketree():
    p = Turtle()
    p.setundobuffer(None)
    p.hideturtle()
    p.speed(0)
    p.getscreen().tracer(30,0)
    p.left(90)
    p.penup()
    p.forward(-210)
    p.pendown()
    t = tree([p], 200, 65, 0.6375)
    for x in t:
        pass
    print(len(p.getscreen().turtles()))
squareTurtle.py 文件源码 项目:Beginners-Python-Examples 作者: AsciiKay 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def square():
    win = turtle.Screen()
    win.bgcolor("white")
    jack = turtle.Turtle()
    for x in range(1,5):
              jack.forward(100)
              jack.right(90)
    win.exitonclick()
tdemo_tree.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def maketree():
    p = Turtle()
    p.setundobuffer(None)
    p.hideturtle()
    p.speed(0)
    p.tracer(30,0)
    p.left(90)
    p.penup()
    p.forward(-210)
    p.pendown()
    t = tree([p], 200, 65, 0.6375)
    for x in t:
        pass
    print len(p.getscreen().turtles())
tdemo_nim.py 文件源码 项目:python2-tracer 作者: extremecoders-re 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def __init__(self, row, col, game):
        turtle.Turtle.__init__(self, visible=False)
        self.row = row
        self.col = col
        self.game = game
        x, y = self.coords(row, col)
        self.shape("square")
        self.shapesize(HUNIT/10.0, WUNIT/20.0)
        self.speed(0)
        self.pu()
        self.goto(x,y)
        self.color("white")
        self.showturtle()
02_drawTriangle.py 文件源码 项目:PythonMaterial 作者: udhayprakash 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def main():
    my_turtle = turtle.Turtle()
    my_win = turtle.Screen()
    my_points = [[-100, -50], [0, 100], [100, -50]]
    sierpinski(my_points, 3, my_turtle)
    my_win.exitonclick()
strokesort.py 文件源码 项目:linedraw 作者: LingDong- 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def visualize(lines):
    import turtle
    wn = turtle.Screen()
    t = turtle.Turtle()
    t.speed(0)
    t.pencolor('red')
    t.pd()
    for i in range(0,len(lines)):
        for p in lines[i]:
            t.goto(p[0]*640/1024-320,-(p[1]*640/1024-320))
            t.pencolor('black')
        t.pencolor('red')
    turtle.mainloop()
??.py 文件源码 项目:MyKnowledge 作者: guofei9987 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def mkHand(name, length):
    # ??Turtle???????Turtle
    turtle.reset()
    Skip(-length * 0.1)
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    turtle.end_poly()
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
tree.py 文件源码 项目:leetcode 作者: misaka-10032 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def drawtree(root):
    def height(root):
        return 1 + max(height(root.left), height(root.right)) if root else -1

    def jumpto(x, y):
        t.penup()
        t.goto(x, y)
        t.pendown()

    def draw(node, x, y, dx):
        if node:
            t.goto(x, y)
            jumpto(x, y - 20)
            t.write(node.val, align='center', font=('Arial', 12, 'normal'))
            draw(node.left, x - dx, y - 60, dx / 2)
            jumpto(x, y - 20)
            draw(node.right, x + dx, y - 60, dx / 2)

    import turtle
    t = turtle.Turtle()
    t.speed(0)
    turtle.delay(0)
    h = height(root)
    jumpto(0, 30 * h)
    draw(root, 0, 30 * h, 40 * h)
    t.hideturtle()
    turtle.mainloop()


问题


面经


文章

微信
公众号

扫码关注公众号