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


Python Turtle.ht方法代码示例

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


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

示例1: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [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 Turtle [as 别名]
# 或者: from turtle.Turtle import ht [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

示例3: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [as 别名]
def main():
    global screen, red, green, blue
    screen = Screen()
    screen.delay(0)
    screen.setworldcoordinates(-1, -0.3, 3, 1.3)

    red = ColorTurtle(0, .5)
    green = ColorTurtle(1, .5)
    blue = ColorTurtle(2, .5)
    setbgcolor()

    writer = Turtle()
    writer.ht()
    writer.pu()
    writer.goto(1,1.15)
    writer.write("DRAG!",align="center",font=("Arial",30,("bold","italic")))
    return "EVENTLOOP"
开发者ID:1c71,项目名称:Program-Practice,代码行数:19,代码来源:海龟-颜色混合.py

示例4: main

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [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:5outh,项目名称:Databases-Fall2014,代码行数:23,代码来源:forest.py

示例5: createPlanetShape

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [as 别名]
def createPlanetShape():
    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:1c71,项目名称:Program-Practice,代码行数:23,代码来源:tdemo_sun_earth.py

示例6: main

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

    planetshape = Shape("compound")
    planetshape.addcomponent(m1,"orange")
    planetshape.addcomponent(m2,"blue")
    s.getscreen().register_shape("planet", planetshape)
    s.getscreen().tracer(1,0)

    ## setup gravitational system
    gs = GravSys()
    sun = Star(1000000, Vec(0,0), Vec(0,-2.5), gs, "circle")
    sun.color("yellow")
    sun.shapesize(1.8)
    sun.pu()
    earth = Star(12500, Vec(210,0), Vec(0,195), gs, "planet")
    earth.pencolor("green")
    earth.shapesize(0.8)
    moon = Star(1, Vec(220,0), Vec(0,295), gs, "planet")
    moon.pencolor("blue")
    moon.shapesize(0.5)
    gs.init()
    gs.start()
    return "Done!"
开发者ID:ChowZenki,项目名称:kbengine,代码行数:40,代码来源:planet_and_moon.py

示例7: Screen

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [as 别名]
import math

screen = Screen()
screenMinX = -screen.window_width() / 2
screenMinY = -screen.window_height() / 2
screenMaxX = screen.window_width() / 2
screenMaxY = screen.window_height() / 2

screen.setworldcoordinates(screenMinX, screenMinY, screenMaxX, screenMaxY)
screen.bgcolor("black")

offscreen_x = screenMinX - 100

t = Turtle()
t.penup()
t.ht()
t.speed(0)
t.goto(0, screenMaxY - 20)
t.color('grey')
t.write("Turtles in Space!!", align="center", font=("Arial", 20))
t.goto(0, screenMaxY - 33)
t.write("Use the arrow keys to move, 'x' to fire, 'q' to quit", align="center")
t.goto(0, 0)
t.color("red")


class Bullet(Turtle):
    def __init__(self, screen, x, y, heading):
        super().__init__()
        self.speed(0)
        self.penup()
开发者ID:mwoinoski,项目名称:crs1906,代码行数:33,代码来源:asteroids.py

示例8: TetrisBoard

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [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

示例9: draw_bullseye

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [as 别名]
	turtle.goto(x, y-radius)
	turtle.pendown()
	turtle.fill(True)
	turtle.circle(radius)
	turtle.fill(False)

def draw_bullseye(turtle, x, y, wn):
	color = True
	for radius in range(circle_radius, circle_inner_radius, -40):
		if color:
			turtle.fillcolor("red")
		else:
			turtle.fillcolor("white")
		origin_circle(turtle,radius,x,y,wn)
		color = not color

while True:
	t1.speed(0)
	wn = t1.getscreen()
	t1.ht()
	width = wn.window_width()
	height = wn.window_height()
	wn.screensize(width, height, None)
	x = randint( -(width/2) + circle_radius, (width/2) - circle_radius)
	y = randint( -(height/2) + circle_radius, (height/2) - circle_radius)
	print x, y
	print width, height
	draw_bullseye(t1, x, y, wn)
	time.sleep(3)
	t1.clear()
开发者ID:camlesom,项目名称:Target-Practice,代码行数:32,代码来源:target.py

示例10: create_turtles

# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import ht [as 别名]
def create_turtles(ne):
    for i in range(ne):
        t = Turtle()
        t.ht()
        t.speed(0)
        t.seth(i * 360.0 / ne)
        t.width(3)
    return s.turtles()
开发者ID:DestinyHe,项目名称:python-turtle-demo,代码行数:10,代码来源:tdemo_wikipedia3.py


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