當前位置: 首頁>>代碼示例>>Python>>正文


Python turtle.Turtle方法代碼示例

本文整理匯總了Python中turtle.Turtle方法的典型用法代碼示例。如果您正苦於以下問題:Python turtle.Turtle方法的具體用法?Python turtle.Turtle怎麽用?Python turtle.Turtle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在turtle的用法示例。


在下文中一共展示了turtle.Turtle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self, game):
        self.game = game
        self.screen = game.screen
        self.model = game.model
        self.screen.colormode(255)
        self.screen.tracer(False)
        self.screen.bgcolor((240, 240, 255))
        self.writer = turtle.Turtle(visible=False)
        self.writer.pu()
        self.writer.speed(0)
        self.sticks = {}
        for row in range(3):
            for col in range(MAXSTICKS):
                self.sticks[(row, col)] = Stick(row, col, game)
        self.display("... a moment please ...")
        self.screen.tracer(True) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:nim.py

示例2: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def main():
    s = Screen()
    s.bgcolor("black")
    p=Turtle()
    p.speed(0)
    p.hideturtle()
    p.pencolor("red")
    p.pensize(3)

    s.tracer(36,0)

    at = clock()
    mn_eck(p, 36, 19)
    et = clock()
    z1 = et-at

    sleep(1)

    at = clock()
    while any([t.undobufferentries() for t in s.turtles()]):
        for t in s.turtles():
            t.undo()
    et = clock()
    return "runtime: %.3f sec" % (z1+et-at) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:26,代碼來源:wikipedia.py

示例3: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def main():
    p = Turtle()
    p.ht()
    tracer(75,0)
    u = doit1(6, Turtle(undobuffersize=1))
    s = doit2(7, Turtle(undobuffersize=1))
    t = doit3(5, Turtle(undobuffersize=1))
    a = clock()
    while True:
        done = 0
        for b in u,s,t:
            try:
                b.__next__()
            except:
                done += 1
        if done == 3:
            break

    tracer(1,10)
    b = clock()
    return "runtime: %.2f sec." % (b-a) 
開發者ID:IronLanguages,項目名稱:ironpython3,代碼行數:23,代碼來源:forest.py

示例4: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
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.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.fps = 30.0 # Lower this on slower computers or with large number of sprites
        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 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:43,代碼來源:spgl.py

示例5: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self,
                text,
                color,
                x = 0,
                y = 0,
                font_name = "Arial",
                font_size = 12,
                font_type = "normal",
                align = "left"):

        turtle.Turtle.__init__(self)
        self.hideturtle()
        self.penup()
        self.goto(x, y)
        self.color(color)
        self.font = (font_name, font_size, font_type)
        self.align = align

        # Attributes
        self.text = text


        # Append to master label list
        Game.labels.append(self) 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:26,代碼來源:spgl.py

示例6: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def main():
    myTurtle = turtle.Turtle()
    myTurtle.speed(0)  # adjust the drawing speed here
    myWin = turtle.Screen()
    
    size = 300
    # 3 points of the first triangle based on [x,y] coordinates
    myPoints = [[0, 0], [0, size], [size, size], [size, 0]]
    
    degree = 1  # Vary the degree of complexity here
    
    # first call of the recursive function
    sierpinski(myPoints, degree, myTurtle)

    myTurtle.hideturtle()  # hide the turtle cursor after drawing is completed
    myWin.exitonclick()  # Exit program when user click on window 
開發者ID:furas,項目名稱:python-examples,代碼行數:18,代碼來源:main.py

示例7: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self, x=0, y=0, dest=None):
        self.t = turtle.Turtle()
        self.t.speed(0)
        
        self.t.up()
        self.t.goto(x, y)
        self.t.down()
        
        if dest is None:
            # use start point as destination point
            self.destination(x, y)
        else:
            self.destination(*dest)
            
        # it is needed by `move` to execute `ontimer`
        self.screen = turtle.Screen()

        # start moving
        self.move() 
開發者ID:furas,項目名稱:python-examples,代碼行數:21,代碼來源:turtle-followed-mouse.py

示例8: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self, pos, dest=None):
        '''create and initiate moth'''
        
        # define turtle 
        self.t = turtle.Turtle()
        self.t.speed(0)

        # it is needed to execute `ontimer`
        self.screen = turtle.Screen()
        
        # remember destination
        self.dest = dest

        # at start it is not fly
        self.is_flying = False        

        # move to start position 
        #(it will use self.dest so it has to be after `self.dest = dest`)
        self.move(pos)
        
        # if destination is set then fly to it
        # (currently it is in `move()`)
        #if self.dest is not None:
        #    self.move_to_light(self.dest) 
開發者ID:furas,項目名稱:python-examples,代碼行數:26,代碼來源:turtle-moth-light.py

示例9: start

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def start():
	# 不顯示繪製時鍾的過程
	turtle.tracer(False)
	turtle.mode('logo')
	createHand('second_hand', 150)
	createHand('minute_hand', 125)
	createHand('hour_hand', 85)
	# 秒, 分, 時
	second_hand = turtle.Turtle()
	second_hand.shape('second_hand')
	minute_hand = turtle.Turtle()
	minute_hand.shape('minute_hand')
	hour_hand = turtle.Turtle()
	hour_hand.shape('hour_hand')
	for hand in [second_hand, minute_hand, hour_hand]:
		hand.shapesize(1, 1, 3)
		hand.speed(0)
	# 用於打印日期等文字
	printer = turtle.Turtle()
	printer.hideturtle()
	printer.penup()
	createClock(160)
	# 開始顯示軌跡
	turtle.tracer(True)
	startTick(second_hand, minute_hand, hour_hand, printer)
	turtle.mainloop() 
開發者ID:CharlesPikachu,項目名稱:Tools,代碼行數:28,代碼來源:clock.py

示例10: maketree

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
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())) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:tree.py

示例11: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def main():
    main = DrawGossip(Turtle())
    long = main.getScreen().numinput("邊長", "請輸入邊長(像素值):", 0, 1, 500)
    linesCount = main.getScreen().numinput("邊數", "多邊形邊的數量:", 3, 3, 100)
    main.drawOctagonalLine(long, linesCount)
    return "EVENTLOOP"

# if __name__ == '__main__':
#     main()
#     TK.mainloop()  # keep window open until user closes it 
開發者ID:rockyCheung,項目名稱:godwill,代碼行數:12,代碼來源:DrawGossip.py

示例12: visualize

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
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() 
開發者ID:LingDong-,項目名稱:linedraw,代碼行數:15,代碼來源:strokesort.py

示例13: square

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
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() 
開發者ID:AsciiKay,項目名稱:Beginners-Python-Examples,代碼行數:10,代碼來源:squareTurtle.py

示例14: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self):
        self.t = turtle.Turtle()
        t = self.t
        t.pensize(3)
        t.speed(9)
        t.ondrag(getPosition) 
開發者ID:PerpetualSmile,項目名稱:Python-Painting-Doraemon,代碼行數:8,代碼來源:Pikachu.py

示例15: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import Turtle [as 別名]
def __init__(self):
		turtle.Turtle.__init__(self)
		self.penup()
		self.shape("invader.gif")
		self.color("green")
		self.frame = 0
		self.frames = ["invader.gif", "invader2.gif"] 
開發者ID:wynand1004,項目名稱:Projects,代碼行數:9,代碼來源:animation6.py


注:本文中的turtle.Turtle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。