本文整理汇总了Python中turtle.Turtle.getscreen方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.getscreen方法的具体用法?Python Turtle.getscreen怎么用?Python Turtle.getscreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.getscreen方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: maketree
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
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
示例2: placeTurtle
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
def placeTurtle(self,x,y):
newT = Turtle()
newTscreen = newT.getscreen()
newTscreen.tracer(0)
newT.up()
newT.goto(x,y)
newT.shape('turtle')
newT.setheading(random.randint(1,359))
newTscreen.tracer(1)
self.numTurtles = self.numTurtles + 1
self.turtleList.append(newT)
if self.numTurtles >= self.maxTurtles:
self.bigTscreen.onclick(None)
示例3: main
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
def main():
s = Turtle()
s.reset()
s.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.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!"
示例4: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
class ThreeTowers:
def __init__(self,numDisks):
self.numDisks = numDisks
self.t = Turtle()
self.screen = self.t.getscreen()
self.height = self.screen.window_height()
self.width = self.screen.window_width()
self.threePoles = [-self.width/4, 0, self.width/4]
self.towers = [Stack(),Stack(), Stack()]
self.largestDisk = self.width/3
self.diskHeight = self.height/100
for i in range(numDisks):
disk = Disk(self.largestDisk/(i+2),self.diskHeight ,self.threePoles[0],0 + self.diskHeight*i)
disk.drawDisk('blue')
self.towers[0].push(disk)
示例5: drawgrid
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
def drawgrid(size):
myturtle = Turtle()
mysreen = myturtle.getscreen()
mysreen.setworldcoordinates(-1, -1, size + 1, size + 1)
myturtle.setx(0)
myturtle.sety(0)
for i in range(size - 1):
myturtle.forward(size - 1)
myturtle.sety(i + 1)
myturtle.setx(0)
myturtle.setx(0)
myturtle.sety(0)
myturtle.left(90)
for i in range(size - 1):
myturtle.forward(size - 1)
myturtle.setx(i + 1)
myturtle.sety(0)
return myturtle, mysreen
示例6: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
class TurtlePlace:
def __init__(self,maxTurtles,hWall=200,vWall=200):
self.bigT = Turtle()
self.bigTscreen = self.bigT.getscreen()
self.bigT.shape('turtle')
self.turtleList = []
self.bigTscreen.onclick(self.placeTurtle)
self.bigT.hideturtle()
self.numTurtles = 0
self.maxTurtles = maxTurtles
self.hWall = hWall
self.vWall = vWall
self.drawField(hWall,vWall)
mainloop()
def placeTurtle(self,x,y):
newT = AnimatedTurtle(self.hWall,self.vWall)
newTscreen = newT.getscreen()
newTscreen.tracer(0)
newT.up()
newT.goto(x,y)
newT.shape('turtle')
newT.setheading(random.randint(1,359))
newTscreen.tracer(1)
self.numTurtles = self.numTurtles + 1
self.turtleList.append(newT)
if self.numTurtles >= self.maxTurtles:
self.bigTscreen.onclick(None)
def drawField(self,hWall,vWall):
self.bigTscreen.tracer(0)
self.bigT.up()
self.bigT.goto(-hWall,-vWall)
self.bigT.down()
for i in range(4):
self.bigT.forward(2*hWall)
self.bigT.left(90)
self.bigTscreen.tracer(1)
示例7: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
class KeysMouseEvents:
def __init__(self):
super().__init__()
self.reinit()
def reinit(self):
self.T=Turtle()
self.screen=self.T.getscreen()
self.screen.onclick(self.drawcir)
self.screen.onkey(self.clear,"c")
self.T.pensize(5)
self.screen.listen()
self.count=0
self.firstx=0
self.firsty=0
self.secondx=0
self.secondy=0
self.T.hideturtle()
self.T.up()
def clear(self):
self.T.screen.clear()
self.reinit()
def drawcir(self,x,y):
self.count = (self.count + 1)
if self.count == 1:
self.T.color("black")
self.firstx=x
self.firsty=y
self.T.goto(x,y)
self.T.down()
self.T.dot()
self.T.up()
return
if self.count == 2:
self.secondx=x
self.secondy=y
X = self.secondx - self.firstx
Y = self.secondy - self.firsty
d = X * X + Y * Y
self.T.color("black")
radious = math.sqrt (d);
self.T.goto(self.firstx, self.firsty-radious)
self.T.down()
self.T.circle(radious)
self.T.up()
c = random.randint(1, 4)
if c == 1:
self.T.color("red")
if c == 2:
self.T.color("green")
if c == 3:
self.T.color("blue")
if c == 4:
self.T.color("yellow")
self.T.begin_fill()
radious=radious-4
self.T.goto(self.firstx, self.firsty-radious)
self.T.down()
self.T.circle(radious)
self.T.end_fill()
self.T.up()
self.T.color("black")
self.T.goto(self.firstx,self.firsty)
self.T.down()
self.T.dot()
self.T.up()
self.count=0
def main(self):
mainloop()
示例8: draw_bullseye
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [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()
示例9: __init__
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import getscreen [as 别名]
class KeysMouseEvents:
def __init__(self):
super().__init__()
self.reinit()
def reinit(self):
self.T=Turtle()
self.screen=self.T.getscreen()
self.screen.onclick(self.drawcir)
self.screen.onkey(self.clear,"c")
self.T.pensize(5)
self.screen.listen()
self.count=0
self.firstx=0
self.firsty=0
self.secondx=0
self.secondy=0
self.T.hideturtle()
self.T.up()
def clear(self):
self.T.screen.clear()
self.reinit()
def drawcir(self,x,y):
self.count = (self.count + 1)
if self.count == 1:
self.T.color("black")
self.firstx=x
self.firsty=y
self.T.goto(x,y)
self.T.down()
self.T.dot()
self.T.up()
return
if self.count == 2:
self.secondx=x
self.secondy=y
X = self.secondx - self.firstx
Y = self.secondy - self.firsty
d = X * X + Y * Y
self.T.color("black")
radius = math.sqrt (d);
len = math.sqrt (2*radius*radius)
a = len/2
b = math.sqrt((radius*radius)-(a*a))
self.T.goto(self.firstx-radius, self.firsty+radius)
self.T.down()
width = 2*radius
height = 2*radius
self.T.speed(0)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.up()
x = random.randint(1, 7)
c = x
if c == 1:
self.T.color("red")
if c == 2:
self.T.color("green")
if c == 3:
self.T.color("blue")
if c == 4:
self.T.color("yellow")
if c == 5:
self.T.color("white")
if c == 6:
self.T.color("pink")
if c == 7:
self.T.color("brown")
if c == 8:
self.T.color("purple")
if c == 9:
self.T.color("gray")
if c == 10:
self.T.color("orange")
self.T.begin_fill()
radius1=radius-4
self.T.goto(self.firstx-radius1, self.firsty+radius1)
self.T.down()
width = 2*radius1
height = 2*radius1
self.T.speed(0)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
self.T.forward(width)
self.T.right(90)
self.T.forward(height)
self.T.right(90)
#.........这里部分代码省略.........