当前位置: 首页>>代码示例>>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;未经允许,请勿转载。