Python turtle.Turtle() Examples
The following are 30
code examples of turtle.Turtle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
turtle
, or try the search function
.
Example #1
Source File: turtle-followed-mouse.py From python-examples with MIT License | 10 votes |
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()
Example #2
Source File: clock.py From Tools with MIT License | 8 votes |
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()
Example #3
Source File: wikipedia.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 7 votes |
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)
Example #4
Source File: wikipedia.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #5
Source File: forest.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #6
Source File: nim.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: spgl.py From SPGL with GNU General Public License v3.0 | 6 votes |
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)
Example #8
Source File: main.py From python-examples with MIT License | 6 votes |
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
Example #9
Source File: nim.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #10
Source File: turtle-moth-light.py From python-examples with MIT License | 6 votes |
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)
Example #11
Source File: Turtle_Mini_Project_KC.py From Python-first-Practice with MIT License | 6 votes |
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()
Example #12
Source File: forest.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: falling_apples.py From Projects with GNU General Public License v3.0 | 5 votes |
def __init__( self ,spriteshape,color,startx,starty): turtle.Turtle.__init__(self, shape = spriteshape) self.speed(0) self.penup() self.color(color) self.goto(startx,starty) self.speed= 1
Example #14
Source File: tree.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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()))
Example #15
Source File: nim.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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()
Example #16
Source File: example-1.py From python-examples with MIT License | 5 votes |
def on_click_2(x, y): print('Turtle 2 clicked:', x, y)
Example #17
Source File: example-1.py From python-examples with MIT License | 5 votes |
def on_click_1(x, y): print('Turtle 1 clicked:', x, y)
Example #18
Source File: Pikachu.py From Python-Painting-Doraemon with MIT License | 5 votes |
def __init__(self): self.t = turtle.Turtle() t = self.t t.pensize(3) t.speed(9) t.ondrag(getPosition)
Example #19
Source File: animation6.py From Projects with GNU General Public License v3.0 | 5 votes |
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"]
Example #20
Source File: space_station_defense_game.py From Projects with GNU General Public License v3.0 | 5 votes |
def __init__(self): turtle.Turtle.__init__(self) # Maximum animation speed self.speed(0) self.penup()
Example #21
Source File: spiro.py From Python-Project with Apache License 2.0 | 5 votes |
def __init__(self,xc,yc,col,R,r,l): self.t=turtle.Turtle() # set the cursor shape self.t.shape('turtle') # set the step in degrees self.step=5 # set the drawing complete flag self.drawingComplete=False # set the paprameters self.setparams(xc,yc,col,R,r,l) # initialize the drawing self.restart()
Example #22
Source File: spgl.py From Projects with GNU General Public License v3.0 | 5 votes |
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
Example #23
Source File: spgl.py From Projects with GNU General Public License v3.0 | 5 votes |
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)
Example #24
Source File: main-3.py From python-examples with MIT License | 5 votes |
def __init__(self, x, y): self.t = turtle.Turtle() self.t.speed(0) self.t.up() self.t.goto(x, y) self.t.down() self.running = True
Example #25
Source File: turtle-on-mouse-move.py From python-examples with MIT License | 5 votes |
def __init__(self, pos): self._turtle = turtle.Turtle() # move to initial position self._turtle.speed(0) # fastest self._turtle.up() self._turtle.setposition(pos) self._turtle.down()
Example #26
Source File: turtle-followed-mouse-2.py From python-examples with MIT License | 5 votes |
def __init__(self, x=0, y=0, dest=None): self.t = turtle.Turtle() self.t.speed(1) self.t.up() self.t.setposition(x, y) self.t.down() if dest is not None: self.destination(*dest)
Example #27
Source File: spgl.py From SPGL with GNU General Public License v3.0 | 5 votes |
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)
Example #28
Source File: forest.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #29
Source File: nim.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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()
Example #30
Source File: nim.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)