Python turtle.tracer() Examples

The following are 13 code examples of turtle.tracer(). 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: clock.py    From Tools with MIT License 8 votes vote down vote up
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 #2
Source File: mandelbrot.py    From advancedpython3 with GNU General Public License v3.0 6 votes vote down vote up
def setup_screen(title, background='white', screen_size_x=640, screen_size_y=320, tracer_size=200):
    print('Set up Screen')
    turtle.title(title)
    turtle.setup(screen_size_x, screen_size_y)
    turtle.hideturtle()
    turtle.penup()
    turtle.backward(240)
    turtle.tracer(tracer_size)
    turtle.bgcolor(background)  # Set the background colour of the screen 
Example #3
Source File: Pikachu.py    From Python-Painting-Doraemon with MIT License 6 votes vote down vote up
def leftCheek(self, x, y):
        turtle.tracer(False)
        t = self.t
        self.noTrace_goto(x, y)
        t.seth(300)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True) 
Example #4
Source File: Pikachu.py    From Python-Painting-Doraemon with MIT License 6 votes vote down vote up
def rightCheek(self, x, y):
        t = self.t
        turtle.tracer(False)
        self.noTrace_goto(x, y)
        t.seth(60)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True) 
Example #5
Source File: clock.py    From Tools with MIT License 5 votes vote down vote up
def startTick(second_hand, minute_hand, hour_hand, printer):
	today = datetime.datetime.today()
	second = today.second + today.microsecond * 1e-6
	minute = today.minute + second / 60.
	hour = (today.hour + minute / 60) % 12
	# 设置朝向
	second_hand.setheading(6 * second)
	minute_hand.setheading(6 * minute)
	hour_hand.setheading(12 * hour)
	turtle.tracer(False)
	printer.forward(65)
	printer.write(getWeekday(today), align='center', font=("Courier", 14, "bold"))
	printer.forward(120)
	printer.write('12', align='center', font=("Courier", 14, "bold"))
	printer.back(250)
	printer.write(getDate(today), align='center', font=("Courier", 14, "bold"))
	printer.back(145)
	printer.write('6', align='center', font=("Courier", 14, "bold"))
	printer.home()
	printer.right(92.5)
	printer.forward(200)
	printer.write('3', align='center', font=("Courier", 14, "bold"))
	printer.left(2.5)
	printer.back(400)
	printer.write('9', align='center', font=("Courier", 14, "bold"))
	printer.home()
	turtle.tracer(True)
	# 100ms调用一次
	turtle.ontimer(lambda: startTick(second_hand, minute_hand, hour_hand, printer), 100) 
Example #6
Source File: snowflake_koch.py    From advancedpython3 with GNU General Public License v3.0 5 votes vote down vote up
def setup_screen(title, background='white', screen_size_x=640, screen_size_y=320, tracer_size=800):
    print('Set up Screen')
    turtle.title(title)
    turtle.setup(screen_size_x, screen_size_y)
    turtle.hideturtle()
    turtle.penup()
    turtle.backward(240)
    # Batch drawing to the screen for faster rendering
    turtle.tracer(tracer_size)
    turtle.bgcolor(background)  # Set the background colour of the screen 
Example #7
Source File: snowflake.py    From advancedpython3 with GNU General Public License v3.0 5 votes vote down vote up
def setup_screen(title, background = 'white'):
    print('Set up Screen')
    turtle.title(title)
    turtle.setup(640, 600)
    turtle.hideturtle()
    turtle.penup()
    turtle.tracer(200)
    turtle.bgcolor(background)  # Set the background colour of the screen 
Example #8
Source File: fractal_trees.py    From advancedpython3 with GNU General Public License v3.0 5 votes vote down vote up
def setup_screen(title, background='white', screen_size_x=640, screen_size_y=320, tracer_size=200):
    """ Sets up Turtle screen with useful defaults """
    print('Set up Screen')
    turtle.title(title)
    turtle.setup(screen_size_x, screen_size_y)
    turtle.hideturtle()
    turtle.penup()
    turtle.backward(240)
    turtle.tracer(tracer_size)
    turtle.bgcolor(background)  # Set the background colour of the screen 
Example #9
Source File: maze.py    From Particle_Filter with MIT License 5 votes vote down vote up
def show_maze(self):

        turtle.setworldcoordinates(0, 0, self.width * 1.005, self.height * 1.005)

        wally = turtle.Turtle()
        wally.speed(0)
        wally.width(1.5)
        wally.hideturtle()
        turtle.tracer(0, 0)

        for i in range(self.num_rows):
            for j in range(self.num_cols):
                permissibilities = self.permissibilities(cell = (i,j))
                turtle.up()
                wally.setposition((j * self.grid_width, i * self.grid_height))
                # Set turtle heading orientation
                # 0 - east, 90 - north, 180 - west, 270 - south
                wally.setheading(0)
                if not permissibilities[0]:
                    wally.down()
                else:
                    wally.up()
                wally.forward(self.grid_width)
                wally.setheading(90)
                wally.up()
                if not permissibilities[1]:
                    wally.down()
                else:
                    wally.up()
                wally.forward(self.grid_height)
                wally.setheading(180)
                wally.up()
                if not permissibilities[2]:
                    wally.down()
                else:
                    wally.up()
                wally.forward(self.grid_width)
                wally.setheading(270)
                wally.up()
                if not permissibilities[3]:
                    wally.down()
                else:
                    wally.up()
                wally.forward(self.grid_height)
                wally.up()

        turtle.update() 
Example #10
Source File: spgl.py    From SPGL with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #11
Source File: spgl.py    From SPGL with GNU General Public License v3.0 5 votes vote down vote up
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 #12
Source File: spgl.py    From Projects with GNU General Public License v3.0 5 votes vote down vote up
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 #13
Source File: circles-picture.py    From advancedpython3 with GNU General Public License v3.0 4 votes vote down vote up
def setup_window():
    # Set up the window
    turtle.title('Circles in My Mind')
    turtle.setup(WIDTH, HEIGHT, 0, 0)
    turtle.colormode(255)  # Indicates RGB numbers will be in the range 0 to 255
    turtle.hideturtle()
    # Batch drawing to the screen for faster rendering
    turtle.tracer(2000)

    # Speed up drawing process
    turtle.speed(10)
    turtle.penup()