本文整理汇总了Python中turtle.Turtle类的典型用法代码示例。如果您正苦于以下问题:Python Turtle类的具体用法?Python Turtle怎么用?Python Turtle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Turtle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, lmbda, mu, queue, server, speed):
"""
Arguments:
lmbda: arrival rate (float)
interarrivaltime: a randomly sampled interarrival time (negative exponential for now)
mu: service rate (float)
service: a randomly sampled service time (negative exponential for now)
queue: a queue object
shape: the shape of our turtle in the graphics (a circle)
server: a server object
served: a boolean that indicates whether or not this player has been served.
speed: a speed (integer from 0 to 10) to modify the speed of the graphics
balked: a boolean indicating whether or not this player has balked (not actually needed for the base Player class... maybe remove... but might be nice to keep here...)
"""
Turtle.__init__(self) # Initialise all base Turtle attributes
self.interarrivaltime = randexp(lmbda)
self.lmbda = lmbda
self.mu = mu
self.queue = queue
self.served = False
self.server = server
self.servicetime = randexp(mu)
self.shape('circle')
self.speed(speed)
self.balked = False
示例2: __init__
def __init__(self, distance, color, speed):
Turtle.__init__(self)
self.pencolor(color)
self.speed = speed
self.penup()
self.forward(distance)
self.pendown()
示例3: init_drawman
def init_drawman():
global t, x_current, y_current
t=Turtle()
t.penup()
x_current = 0
y_current = 0
t.goto(x_current,y_current)
示例4: __init__
def __init__(self, bilddatei, game):
Turtle.__init__(self, bilddatei)
self.game = game
self.penup()
self.speed(0)
self.onclick(self.hit)
self.start()
示例5: main
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)
示例6: __init__
def __init__(self, start=(10,10), end=(160,160),
width=200, height=200):
Turtle.__init__(self)
self.hideturtle()
self.screen.bgcolor("blue")
self.screen.setworldcoordinates(-DISTANCE, -DISTANCE,
DISTANCE+width,
DISTANCE+height)
self.screen.tracer(30,0)
self.pensize(5)
self.color("white", "black")
lab = {start}
while True:
new_points = set()
for point in lab:
x,y = map(add, point, choice(WAYS))
if (0 <= x <= width and
0 <= y <= height and
(x,y) not in lab and
(x,y) not in new_points):
self.penup()
self.goto(*point)
self.pendown()
self.goto(x,y)
new_points.add((x,y))
if new_points or end not in lab:
lab |= new_points
else:
break
self.mark_targets(start, end)
self.maze_map = lab
self.start = start
self.end = end
print("KONEC")
示例7: draw_figures
def draw_figures(figures):
for figure in figures:
t = Turtle()
t.speed('slow')
figure.draw_figure(t)
done()
示例8: LSystem
class LSystem(object):
def __init__(self):
self.turtle = Turtle()
def reset(self):
self.turtle.reset()
def set_lsystem(self,lsystem):
self.axiom,self.rules,self.angle = lsystem
self.segment_length=5
def generate(self,generations_num):
def generate_help(start):
for e in start:
for r in self.rules.get(e,e):
yield r
if generations_num==0: return self.axiom
return generate_help(self.generate(generations_num-1))
def draw(self,generations,chunk_size):
iterable = interpret(self.turtle,self.generate(generations),self.angle)
l=[]
for e in iterable:
l.append(e)
if len(l)==chunk_size:
yield l
l=[]
if l: yield l
示例9: __init__
def __init__(self):
Turtle.__init__(self)
self.up()
self.setheading(random.randrange(360))
self.setpos(random.randrange(-200,200),random.randrange(-200,200))
self.down()
self.newHead = None
Schooler.swarm.append(self)
示例10: init_drawman
def init_drawman():
global x_current, y_current, t, _drawman_scale
t=Turtle()
t.penup()
x_current=0
y_current=0
t.goto(x_current,y_current)
drawman_scale(default_scale) # функция задает масштаб по умолчанию
示例11: test_segments_stored
def test_segments_stored(self):
"""With branching, some points exist"""
my_turtle = Turtle()
my_turtle.speed(0)
my_tree = Tree()
my_tree.draw(my_turtle, max_depth=1)
self.assertTrue(len(my_tree.segments) > 0, "Some segments should be stored")
示例12: init_drawman
def init_drawman():
global t, x_current, y_current, _drawman_scale
t=Turtle()
t.penup()
x_current = 0
y_current = 0
t.goto(x_current, y_current)
drawman_scale(default_scale)
示例13: main
def main():
dimension = int(input('Enter dimension: '))
t = Turtle()
t.speed('fastest')
t.pensize(3)
draw_table(dimension, 50, t, -200, 300)
示例14: __init__
def __init__(self, col, row):
Turtle.__init__(self)
self.speed(0)
self.pu()
self.shape("square")
self.color("black", "")
self.shapesize((BLOCKWIDTH-1)/20., (BLOCKWIDTH-1)/20., 1)
self.goto(-COLUMNS*BLOCKWIDTH/2+14+col*BLOCKWIDTH, ROWS*BLOCKWIDTH/2 - 14 - row*BLOCKWIDTH)
示例15: test_points_stored
def test_points_stored(self):
"""After one iteration, as least a trunk segment should be stored"""
my_turtle = Turtle()
my_turtle.speed(0)
my_tree = Tree()
my_tree.draw(my_turtle, max_depth=1)
# whitebox
self.assertTrue(len(my_tree._points) > 0, "Some points should be stored")