本文整理汇总了Python中turtle.xcor函数的典型用法代码示例。如果您正苦于以下问题:Python xcor函数的具体用法?Python xcor怎么用?Python xcor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xcor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawIt
def drawIt(backAgain):
turtle.penup()
turtle.setpos(0,vertHeight)
turtle.pendown()
upDown = True
start = turtle.xcor()
for i in range(iterLength):
randomyUpDownVariance = randint(1,55)
randomyBetweenLineVariance = randint(1,25)
randPenSize = randint(2,10)
randPenColor1 = randint(1,187)
randPenColor2 = randint(1,193)
randPenColor3 = randint(1,182)
turtle.pensize(randPenSize)
print turtle.xcor()
tup = (randPenColor1, randPenColor2, randPenColor3)
turtle.pencolor(tup)
if upDown == True:
upDown = False
turtle.goto(start, (vertHeight + randomyUpDownVariance))
elif upDown == False:
upDown = True
turtle.goto(start, -(vertHeight + randomyUpDownVariance))
if backAgain == True:
start -= randomyBetweenLineVariance
elif backAgain == False:
start += randomyBetweenLineVariance
if (backAgain == True):
drawIt(False)
示例2: verificarPos
def verificarPos(self):
"""
Desc: Método para verificar se a posição e sentido da tartaruga é igual ao inicial
Use getPos() para pegar o inicial
Printa: String = Erro
Retorna: Boolean = True (caso esteja ok) ou False (caso não)
Exemplo:
cb.getPos()
cb.casa(25, 50, 30)
cb.verificarPos()
"""
self._retorno = True
if (round(turtle.xcor()) != self.turtlePosX) or (round(turtle.ycor()) != self.turtlePosY):
print("A posição atual da tartaruga difere da inicial ({0}, {1})\nEla está em: ({2}, {3})".format(str(self.turtlePosX),
str(self.turtlePosY),
str(round(turtle.xcor())),
str(round(turtle.ycor()))))
self._retorno = False
if turtle.heading() != self.turtleDir:
print("A direção atual da tartaruga difere da inicial (" + str(self.turtleDir) + ")\nEla está em:", str(turtle.heading()))
self._retorno = False
return self._retorno
示例3: d
def d(fill=False):
'''draws a capital D'''
turtle.setheading(0)
if fill: bf()
fd(20)
circle(20, 90)
fd(70)
circle(20, 90)
fd(20)
lt(90)
fd(110)
lt(90)
if fill: ef()
pu()
turtle.goto(turtle.xcor() + 10, turtle.ycor() + 10)
pd()
cfc = fc()
fc(turtle.getscreen().bgcolor())
bf()
fd(10)
circle(10, 90)
fd(70)
circle(10, 90)
fd(10)
lt(90)
fd(90)
ef()
lt(90)
pu()
turtle.goto(turtle.xcor() + 40, turtle.ycor() - 10)
pd()
fc(cfc)
示例4: checkxbound
def checkxbound():
if turtle.xcor() > (wn.screensize()[0]/2):
return 1
elif turtle.xcor() < (wn.screensize()[0]/-2):
return 2
else:
return 0
time.sleep(1)
示例5: gotoandprint
def gotoandprint(x, y):
turtle.goto(x, y)
#time.sleep(10)
print()
print("Set hook:")
print(turtle.xcor(), turtle.ycor())
x=turtle.xcor()
y=turtle.ycor()
coordinate=[x,y]
return coordinate
示例6: a
def a(fill=False):
'''draws a capital A.'''
turtle.setheading(0)
if fill: bf()
fd(10)
turtle.goto(turtle.xcor() + 5, turtle.ycor() + 40)
fd(10)
turtle.goto(turtle.xcor() + 5, turtle.ycor() - 40)
fd(10)
turtle.goto(turtle.xcor() - 15, turtle.ycor() + 110)
turtle.setx(turtle.xcor() - 10)
turtle.goto(turtle.xcor() - 15, turtle.ycor() - 110)
if fill: ef()
pu()
turtle.goto(turtle.xcor() + 17, turtle.ycor() + 50)
pd()
if fill:
cfc = fc()
fc(turtle.getscreen().bgcolor())
bf()
fd(6)
turtle.goto(turtle.xcor() - 3, turtle.ycor() + 40)
turtle.goto(turtle.xcor() - 3, turtle.ycor() - 40)
if fill:
ef()
fc(cfc)
pu()
turtle.goto(turtle.xcor() + 33, turtle.ycor() - 50)
pd()
示例7: draw_backward_e
def draw_backward_e(x,y,h=100):
if x == None:
x = turtle.xcor()
y = turtle.xcor()
go(x,y)
turtle.goto(x+h/2 ,y)
turtle.goto(x+h/2,h/2+y)
turtle.goto(x,h/2+y)
turtle.goto(x+h/2,y+h/2)
turtle.goto(x+h/2,y+h)
turtle.goto(x,y+h)
go(x+h,y)
示例8: numberXtickers
def numberXtickers():
current = xscale*(xmin//xscale)
tickerLength = float(ymax-ymin)/40
while current < xmin:
current += xscale
toXY(current,-2*tickerLength)
while current <= xmax:
if turtle.xcor() != 0:
turtle.write(turtle.xcor(),align="center",font=("Arial",12,"normal"))
current += xscale
toXY(current,-2*tickerLength)
示例9: tree
def tree():
'''draw a tree'''
oc = color()
fc('saddle brown')
bf()
turtle.goto(turtle.xcor()+20,turtle.ycor())
turtle.goto(turtle.xcor(),turtle.ycor()+80)
turtle.goto(turtle.xcor()-20,turtle.ycor())
turtle.goto(turtle.xcor(),turtle.ycor()-80)
ef()
fc('dark green')
color('dark green')
pu()
turtle.goto(turtle.xcor()+10,turtle.ycor()+80)
pd()
bf()
circle(20)
ef()
turtle.goto(turtle.xcor()-20,turtle.ycor()-20)
bf()
circle(20)
ef()
pu()
turtle.goto(turtle.xcor()+40,turtle.ycor())
pd()
bf()
circle(20)
ef()
pu()
turtle.goto(turtle.xcor()-30,turtle.ycor()-60)
pd()
color(oc[0])
fc(oc[1])
示例10: passeio
def passeio(dim, lado, passos):
# Prepara grelha
turtle.speed(0)
grelha_2(dim,lado)
turtle.color('red')
turtle.home()
turtle.pendown()
# Passeio
turtle.speed(6)
turtle.dot()
turtle.showturtle()
lim_x = lim_y = (dim*lado)//2
cor_x = 0
cor_y = 0
for i in range(passos):
vai_para = random.choice(['N','E','S','W'])
if (vai_para == 'N') and (cor_y < lim_y):
cor_y += lado
turtle.setheading(90)
turtle.fd(lado)
elif (vai_para == 'E') and (cor_x < lim_x):
cor_x += lado
turtle.setheading(0)
turtle.fd(lado)
elif (vai_para == 'S') and (cor_y > -lim_y):
cor_y -= lado
turtle.setheading(270)
turtle.fd(lado)
elif (vai_para == 'W') and (cor_x > -lim_x):
cor_x -= lado
turtle.setheading(180)
turtle.fd(lado)
else:
print((vai_para,turtle.xcor(),turtle.ycor()))
continue
示例11: drawHouse
def drawHouse(wallSize):
"""
This is the function for drawing house which takes
wall size as a input.
:pre: (relative) pos (0,0), heading (east), right
:post: (relative) pos (wallSize,0), heading (north), up
:return: total wood required to built the house.
"""
turtle.down()
turtle.forward(wallSize)
turtle.left(90)
turtle.forward(wallSize)
maxX = turtle.xcor()
turtle.left(45)
turtle.forward(wallSize / math.sqrt(2))
maxY = turtle.ycor()
turtle.left(90)
turtle.forward(wallSize / math.sqrt(2))
turtle.left(45)
turtle.forward(wallSize)
turtle.left(90)
turtle.forward(wallSize)
turtle.up()
return 2 * (wallSize + wallSize / math.sqrt(2))
示例12: main
def main():
drawEnd = False
while drawEnd == False:
if turtle.xcor() < xEndPoint and turtle.ycor() < yEndPoint:
randDir = None
while randDir == None:
randDir = randomDirection()
moveTurtle(turtle, randDir)
elif turtle.xcor() < xEndPoint:
moveTurtle(turtle, EAST)
elif turtle.ycor() < yEndPoint:
moveTurtle(turtle, NORTH)
else:
drawEnd = True
示例13: printwin
def printwin(turtle):
turtle.stamp()
turtle.hideturtle()
turtle.penup()
turtle.goto(turtle.xcor(),turtle.ycor() + 15)
turtle.color("green")
turtle.write("You Win!",font=("Arial",30), align = "center")
示例14: collision_check
def collision_check(self, turtle):
self._turtlex = turtle.xcor()
self._turtley = turtle.ycor()
self._dist = (((self._x1 - self._x2)**2 + (self._y1 - self._y2)**2)**0.5)
self._dist2 = (((self._x1 - self._turtlex)**2 + (self._y1 - self._turtley)**2)**0.5)
self._dist3 = (((self._turtlex - self._x2)**2 + (self._turtley - self._y2)**2)**0.5)
if(self._dist2 + self._dist3 == self._dist):
return True
示例15: draw_star
def draw_star(size, color):
# from center move to left vertex
tt.setpos(tt.xcor()-size/2.0, tt.ycor()+size/2.0/math.tan(math.radians(72.0)))
tt.fillcolor(color)
tt.begin_fill()
for i in range(5):
tt.forward(size/2.0/(1+math.sin(math.radians(18))))
tt.left(72)
tt.forward(size/2.0/(1+math.sin(math.radians(18))))
tt.right(180-36)
tt.end_fill()
# back to center
tt.setpos(tt.xcor()+size/2.0, tt.ycor()-size/2.0/math.tan(math.radians(72.0)))