当前位置: 首页>>代码示例>>Python>>正文


Python Screen.tracer方法代码示例

本文整理汇总了Python中turtle.Screen.tracer方法的典型用法代码示例。如果您正苦于以下问题:Python Screen.tracer方法的具体用法?Python Screen.tracer怎么用?Python Screen.tracer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在turtle.Screen的用法示例。


在下文中一共展示了Screen.tracer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def main():
    global screen
    screen = Screen()
    screen.colormode(255)
    p = Turtle()
    p.ht()
    screen.tracer(75,0)
    u = doit1(6, Turtle(undobuffersize=1))
    s = doit2(7, Turtle(undobuffersize=1))
    t = doit3(5, Turtle(undobuffersize=1))
    v = doit4(6, Turtle(undobuffersize=1))
    w = doit5(5, Turtle(undobuffersize=1))
    a = clock()
    while True:
        done = 0
        for b in u,s,t,v,w:
            try:
                next(b)
            except:
                done += 1
        if done == 5:
            break

    screen.tracer(1,10)
    b = clock()
    return "runtime: {0:.2f} sec.".format(b-a)
开发者ID:1c71,项目名称:Program-Practice,代码行数:28,代码来源:tdemo_another_forest.py

示例2: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def main():
    global s
    at = clock()
    s = Screen()
    s.bgcolor("black")
    s.tracer(36, 0)
    mn_eck(36, 19)
    et = clock()
    return "Laufzeit: %.3f sec" % (et - at)
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:11,代码来源:tdemo_wikipedia3.py

示例3: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def main():
    global s, t
    s = Screen()
    s.bgcolor("gray10")
    t = Turtle(visible=False, shape="square")
    t.pu()
    t.speed(0)
    s.tracer(False)
    ta = clock()
    recsquare(256, 0.5, colors)
    tb = clock()
    return "{0:.2f}sec.".format(tb-ta)
开发者ID:1c71,项目名称:Program-Practice,代码行数:14,代码来源:tdemo_recursive_squares.py

示例4: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def main():
    ## create compound yellow/blue turtleshape for planets
    global s
    s = Screen()
    s.setup(1120,840)
    s.reset()
    s.tracer(0, 0)
    t = Turtle()
    t.ht()
    t.pu()
    t.fd(6)
    t.lt(90)

    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m1 = t.get_poly()

    t.begin_poly()
    t.circle(6,180)
    t.end_poly()
    m2 = t.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1,"orange")
    planetshape.addcomponent(m2,"blue")
    s.register_shape("planet", planetshape)
    #s.tracer(1,0)
    s.update()
    ## setup gravitational system
    gs = GravSys()
    sun = Star(1000000, Vec(-250,0), Vec(0,-0.35), gs, "circle")
    sun.color("yellow")
    sun.pensize(1.8)
    sun.pu()
    earth = Star(5000, Vec(450,0), Vec(0,70), gs, "planet")
    earth.pencolor("green")
    earth.shapesize(0.8)

    rm=12.0583
    vm=(8.0*5000/rm)**.5
    moon = Star(1, Vec(450+rm,0), Vec(0,70+vm), gs, "planet")
    moon.pencolor("blue")
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    return "Done!"
开发者ID:1c71,项目名称:Program-Practice,代码行数:49,代码来源:planet_and_moon_2.py

示例5: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def main():
    global d, SHS, SF, A
    A = 42  # answer to the ultimate question ... (you know)
    SHS = A / 20.0
    SF = 1.0
    DSF = 1.0038582416
    s = Screen()
    s.setup(800, 600)
    s.reset()
    s.tracer(0)
    d = Turtle(visible=False)
    for i in range(6):
        d.fd(500)
        d.bk(500)
        d.left(60)

    triangles = []
    for c in range(-5, 6, 2):
        if abs(c) != 1:
            triangles.append(TriTurtle(c, 1, 1))
            triangles.append(TriTurtle(c, -1, 2))
    for c in range(-4, 5, 2):
        if c != 0:
            triangles.append(TriTurtle(c, 2, 2))
            triangles.append(TriTurtle(c, -2, 1))
        triangles.append(TriTurtle(c, -4, 2))
        triangles.append(TriTurtle(c, 4, 1))
    for c in range(-3, 4, 2):
        triangles.append(TriTurtle(c, 5, 2))
        triangles.append(TriTurtle(c, -5, 1))
        triangles.append(TriTurtle(c, -7, 2))
        triangles.append(TriTurtle(c, 7, 1))
    for c in range(-2, 3, 2):
        triangles.append(TriTurtle(c, 8, 2))
        triangles.append(TriTurtle(c, -8, 1))
    for c in (-1, 1):
        triangles.append(TriTurtle(c, 1, 1))
        triangles.append(TriTurtle(c, -1, 2))
    triangles.append(TriTurtle(0, 2, 2))
    triangles.append(TriTurtle(0, -2, 1))
    s.tracer(1)

    for phi in range(1, 361):
        SF = SF * DSF
        s.tracer(0)
        for t in triangles:
            t.setturn(phi)
        s.tracer(1)
    return "DONE!"
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:51,代码来源:tdemo_trigeo.py

示例6: createPlanetShape

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
def createPlanetShape():
    s = Screen()
    s.tracer(0, 0)
    t = Turtle()
    t.ht()
    t.pu()
    t.fd(6)
    t.lt(90)
    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m1 = t.get_poly()
    t.begin_poly()
    t.circle(6, 180)
    t.end_poly()
    m2 = t.get_poly()

    planetshape = Shape("compound")
    planetshape.addcomponent(m1, "orange")
    planetshape.addcomponent(m2, "blue")
    s.register_shape("planet", planetshape)
    s.tracer(True, 0)
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:24,代码来源:tdemo_planet.py

示例7: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [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 "Laufzeit: {0:.3f} sec".format(z1+et-at)
开发者ID:1c71,项目名称:Program-Practice,代码行数:26,代码来源:tdemo_wikipedia4.py

示例8: main

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [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:1st1,项目名称:cpython,代码行数:26,代码来源:wikipedia.py

示例9: fire

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]

def fire():
    ship.fireBullet()


def quit():
    turtle.goto(0, screenMaxY - 100)
    turtle.color('green')
    turtle.write("Thanks for playing!", font=("Arial", 30), align="center")
    sleep(1)
    exit()


turtle.hideturtle()

screen.tracer(0);

screen.onkey(turnLeft, 'Left')
screen.onkey(turnRight, 'Right')
screen.onkey(go, 'Up')
screen.onkey(fire, 'x')
screen.onkey(quit, 'q')
screen.listen()

play()

screen.mainloop()

print("Done")
开发者ID:mwoinoski,项目名称:crs1906,代码行数:31,代码来源:asteroids.py

示例10: Screen

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
Inspired by Pawel Boytchev's Elica-Logo
implementation of the tangram game.

Use left mouse button to drag, middle
and right mouse button clicks to turn tiles,
left button doubleclick to flip rhomboid.
"""
from turtle import Turtle, Screen, Vec2D 
from button import Button
import sys, random, time

from tangramdata import tangramdata
sys.setrecursionlimit(20000)
screen = Screen()
screen.tracer(False)
screen.mode("logo")
designer = Turtle(visible=False)
designer.pu()

startdata = tangramdata[0]
tangramdata = tangramdata[1:]
A = 198.0
a = A / 4.0
d = a * 2**.5

def makerhomboidshapes():
    designer.shape("square")
    designer.shapesize(5, 2.5)
    designer.shearfactor(-1)    # needs Python 3.1
    designer.tilt(90)
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:32,代码来源:tangram.py

示例11: TetrisBoard

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
class TetrisBoard(object):
    def __init__(self, cols, rows):
        self.cols, self.rows = cols, rows
        self.screen = Screen()
        self.screen.screensize(BLOCKWIDTH*cols-50, BLOCKWIDTH*rows-50)
        self.screen.setup(BLOCKWIDTH*cols+12, BLOCKWIDTH*rows+12)
        self.screen.title("Turtle Tetris")
        self.screen.bgcolor("black")
        self.writer = Turtle()
        self.writer.ht()        
        self.label = None
        self.grid = {}
        self.screen.tracer(False)
        for row in range(rows):
            for col in range(cols):
                self.grid[(col, row)] = TetrisTurtle(col, row)
        self.screen.tracer(True)
        self.brick = TetrisBrick(self)
        self.result = 0
        self.LEVEL = 0.6
        self.keybuffer = KeyBuffer(self.screen,
                            ["Right", "Left", "Up", "Down", "space", "Escape"])
        self.reset()
        self.screen.listen()
        self.t1 = time()
        
    def reset(self):
        self.result = 0
        self.LEVEL = 0.600
        self.screen.tracer(False)
        self.writer.clear()
        if self.label:
            self.writer.clearstamp(self.label)
        for x in range(COLUMNS):
            for y in range(ROWS):
                self.grid[(x,y)].fillcolor("")
        self.screen.tracer(True)
        self.state = "NEWBRICK"
        
    def blink(self, y, n=1):
        for _ in range(n):
            for color in ("white", "black"):
                self.screen.tracer(False)
                for x in range(COLUMNS):
                    self.grid[(x,y)].pencolor(color)
                    sleep(self.LEVEL/10.0)
                self.screen.tracer(True)
            
    def display_result(self):
        tb = self
        tb.writer.color("white", "gray20")
        tb.writer.shape("square")
        tb.writer.shapesize(5, 15)
        tb.writer.goto(-4 ,0)
        self.label = tb.writer.stamp()
        tb.writer.goto(-2,3)
        tb.writer.write(str(tb.result) + " rows!",
                        align="center", font = ("Courier", 24, "bold") )
        tb.writer.goto(-2,-22)
        tb.writer.write("New game : <spacebar>",
                        align="center", font = ("Courier", 16, "bold") )
        tb.writer.goto(-2,-42)
        tb.writer.write("Quit : <escape>",
                        align="center", font = ("Courier", 16, "bold") )
        
    def getcolor(self, col, row):
        return self.grid[(col, row)].fillcolor()
    def setcolor(self, col, row, color):
        return self.grid[(col, row)].fillcolor(color)
    def rowfree(self, row):
        return not any([self.getcolor(col, row) for col in range(COLUMNS)])
    def rowfull(self, row):
        return all([self.getcolor(col, row) for col in range(COLUMNS)])

    def cleanup(self, shp):
        try:
            ymax = max([y for (x,y) in shp])
        except ValueError:
            self.state = "FINIS"
            return
        currenty = ymax
        while currenty > 0:
            if self.rowfull(currenty):
                self.blink(currenty, 2)
                self.result += 1
                if self.result == 8:
                    self.LEVEL = 0.4
                elif self.result == 20:
                    self.LEVEL = 0.25
                y = currenty
                while True:
                    self.screen.tracer(False)
                    for c in range(COLUMNS):
                        self.setcolor(c, y, self.getcolor(c, y-1))
                    self.screen.tracer(True)
                    if self.rowfree(y):
                        break
                    else:
                        y -= 1
            else:
#.........这里部分代码省略.........
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:103,代码来源:pytetris.py

示例12: fire

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]

def fire():
    ship.fireBullet()


def quit():
    turtle.goto(0, screenMaxY - 100)
    turtle.color("green")
    turtle.write("Thanks for playing!", font=("Arial", 30), align="center")
    sleep(1)
    exit()


turtle.hideturtle()

screen.tracer(0)

screen.onkey(turnLeft, "Left")
screen.onkey(turnRight, "Right")
screen.onkey(go, "Up")
screen.onkey(fire, "x")
screen.onkey(quit, "q")
screen.listen()

play()

screen.mainloop()

print("Done")
开发者ID:mwoinoski,项目名称:crs1906,代码行数:31,代码来源:asteroids.py

示例13: setturn

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
        self.shapesize(SHS, SHS, 1)
        self.D = self.distance(0,0)
        self.e = (1/self.D)*self.pos()
    def setturn(self, phi):
        self.goto(SF*self.D*dsin(90-phi)*self.e)
        self.settiltangle(phi*self.f)
        self.shapesize(SHS*SF)
        if abs(self.c) + abs(self.r) > 2:
            self.fillcolor([x + (1-x)*phi/360 for x in self.basecolor])
            bc = phi/360.
            self.pencolor(bc, bc, bc)
            

s = Screen()
s.reset()
s.tracer(0)
d = Turtle(visible=False)
lines(500)

triangles = []
for c in range(-5,6,2):
    triangles.append(TriTurtle(c, 1, 1))
    triangles.append(TriTurtle(c, -1, 2))
for c in range(-4,5,2):
    triangles.append(TriTurtle(c, 2, 2))
    triangles.append(TriTurtle(c, -2, 1))
    triangles.append(TriTurtle(c, -4, 2))
    triangles.append(TriTurtle(c, 4, 1))
for c in range(-3,4,2):
    triangles.append(TriTurtle(c, 5, 2))
    triangles.append(TriTurtle(c, -5, 1))
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:33,代码来源:trigeo.py

示例14: MazeGraphics

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
class MazeGraphics(object):
    def __init__(self, config):
        self.width = config.getValueAsInt("maze", "maze_size")
        self.height = config.getValueAsInt("maze", "maze_size")
        self.bg_color = config.getValue("maze", "bg_color")
        self.line_color = config.getValue("maze", "line_color")
        self.line_centroid_color = config.getValue("maze", "line_centroid_color")
        self.forward_centroid_color = config.getValue("maze", "forward_centroid_color")
        self.reverse_centroid_color = config.getValue("maze", "reverse_centroid_color")
        self.path_color = config.getValue("maze", "path_color")
        self.screen = Screen()
        self.setupTurtle(self.width, self.height)

    def setupTurtle(self, width, height):
        self.screen.tracer(False)
        self.screen.screensize(width, height)
        # some basic turtle settings
        self.screen.setworldcoordinates(-1, -1, width + 1, height + 1)
        self.screen.title("Random Turtle Maze")
        self.screen.bgcolor(self.bg_color)
        self.screen.delay(None)
        self.designer = Turtle(visible=False)

    def drawGrid(self):
        for i in xrange(0, self.width + 1):
            self.drawXLines(i, self.width, self.line_color)
        for i in xrange(0, self.height + 1):
            self.drawYLines(i, self.width, self.line_color)
        self.screen.update()

    def drawXLines(self, position, width, color):
        self.drawLines(position, 0, width, color, 90)

    def drawYLines(self, position, width, color):
        self.drawLines(0, position, width, color, 0)

    def drawLines(self, xPosition, yPosition, width, color, heading):
        self.designer.up()
        self.designer.setposition(xPosition, yPosition)
        self.designer.color(color)
        self.designer.down()
        self.designer.setheading(heading)
        self.designer.forward(width)
        self.designer.up()

    def drawCentroid(self, cell, color):
        """
        Draw a centroid for animation purposes but then overwrite it.
        """
        self.designer.setposition(cell.centroid)
        self.designer.dot(5, color)
        self.screen.update()
        self.designer.dot(5, self.bg_color)

    def removeWall(self, posx, posy, heading, color):
        """
            We tear down walls to build the maze
        """
        self.designer.up()
        self.designer.setposition(posx, posy)
        self.designer.down()
        self.designer.color(color)
        self.designer.setheading(heading)
        self.designer.forward(1)
        self.designer.up()
        self.screen.update()

    def drawPath(self, cell1, cell2):
        """
            This draws a line for the solution as it's worked out.
        """
        self.designer.setposition(cell1.centroid)
        self.designer.color(self.path_color)
        direction = self.getDirection(cell1, cell2)
        if direction == "N":
            self.designer.setheading(90)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "S":
            self.designer.setheading(270)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "W":
            self.designer.setheading(0)
            self.designer.down()
            self.designer.forward(1)
            self.designer.up()
        elif direction == "E":
            self.designer.setheading(0)
            self.designer.down()
            self.designer.backward(1)
            self.designer.up()
        self.drawCentroid(cell2, self.line_centroid_color)
        self.screen.update()

    def getDirection(self, currCell, nextCell):
        direction = None
        if nextCell.x < currCell.x:
#.........这里部分代码省略.........
开发者ID:skroah,项目名称:pythonmaze,代码行数:103,代码来源:mazegraphics.py

示例15: Screen

# 需要导入模块: from turtle import Screen [as 别名]
# 或者: from turtle.Screen import tracer [as 别名]
from turtle import Screen, Turtle
from random import randint

s = Screen()
s.setup(560,560)
s.title("A drunken turtle collecting ...")

s.tracer(False)
writer = Turtle(visible=False)
writer.penup()
writer.goto(0, -275)

coins = []
for i in range(-4,5):
  for j in range(-4, 5):
      if i == j == 0:
          continue
      c = Turtle(shape="circle")
      c.color("", "orange")
      c.shapesize(0.5)
      c.goto(40*i, 40*j)
      coins.append(c)
s.tracer(True)

DRUNKENNESS = 45       
t = Turtle(shape="turtle")
t.color("black","")
points = 0
while abs(t.xcor()) < 200 and abs(t.ycor()) < 200:
  t.forward(5)
  t.right(randint(-DRUNKENNESS, DRUNKENNESS))
开发者ID:ernestojfcosta,项目名称:IPRP,代码行数:33,代码来源:rqndom_walk.py


注:本文中的turtle.Screen.tracer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。