本文整理汇总了Python中turtle.goto函数的典型用法代码示例。如果您正苦于以下问题:Python goto函数的具体用法?Python goto怎么用?Python goto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了goto函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: line
def line(a1,b1,a2,b2,c):
turtle.pu()
turtle.goto(a1,b1)
turtle.color(c)
turtle.pd()
turtle.pensize(10)
turtle.goto(a2,b2)
示例2: rectangle
def rectangle(length = 50, width = 30, x = 0, y = 0, color = 'black', fill = False):
turtle.pensize(3)
turtle.speed('fastest')
turtle.hideturtle()
if fill == True:
turtle.color(color)
for i in range(width):
turtle.setposition(x, (y+i))
turtle.pendown()
turtle.setposition((x+length), (y+i))
turtle.penup()
else:
turtle.penup()
turtle.goto(x,y)
turtle.color(color)
turtle.pendown()
turtle.forward(length)
turtle.left(90)
turtle.forward(width)
turtle.left(90)
turtle.forward(length)
turtle.left(90)
turtle.forward(width)
turtle.left(90)
turtle.penup()
return
示例3: drawLine
def drawLine(self,color,coord1,coord2):
"""
dessine une ligne entre deux coordonné sur la grille
:param color: La couleur de la ligne
:param coord1: La première coordonné en tuple (i,j,"joueur")
:param coord2: La deuxième coordonné en tuple (i,j,"joueur")
"""
if coord1[2] == coord2[2] and coord2[2] == "you":
turtle.goto(38+coord1[1]*25,87-25*coord1[0])
elif coord1[2] == coord2[2] and coord2[2] == "enemy":
turtle.goto(-262+(25*coord1[1]),87-25*coord1[0])
else:
print('wrong player')
return 0
turtle.pensize(20)
turtle.pencolor(color)
if coord1[1] == coord2[1]: #Vertical
turtle.pendown()
turtle.setheading(270)
turtle.fd((coord2[0]-coord1[0])*25)
elif coord1[0] == coord2[0]: #horizontal
turtle.pendown()
turtle.setheading(0)
turtle.fd((coord2[1]-coord1[1])*25)
else:
print('Ligne non Hori ou Vert')
return 0
turtle.penup()
return 1
示例4: drawmountain
def drawmountain(x,y,color):
t.up
t.goto(x,y)
t.down
t.color(color)
t.begin_fill()
t.backward(200)
t.right(120)
t.backward(200)
t.right(120)
t.backward(200)
t.right(120)
t.end_fill()
t.up
t.goto(x-75,y+125)
t.down
t.color("White")
t.begin_fill()
t.backward(50)
t.right(120)
t.backward(50)
t.right(120)
t.backward(50)
t.right(120)
t.end_fill()
t.up
示例5: entrance
def entrance(pointOne):
turtle.goto(pointOne[0], pointOne[1] + 36)
turtle.setheading(270)
turtle.pendown()
turtle.forward(15)
turtle.penup()
drawArrows()
示例6: draw_path
def draw_path(self, positions):
'''
Draws the path given by a position list
'''
def position_to_turtle(pos):
'''Converts a maze position to a turtle position'''
return (home_x + _DRAW_SIZE * pos[0], home_y - _DRAW_SIZE * pos[1])
# Get maze size
width, height = self.size
# Prepare turtle
home_x = (-(_DRAW_SIZE * width) / 2) + (_DRAW_SIZE / 2)
home_y = ((_DRAW_SIZE * height) / 2) - (_DRAW_SIZE / 2)
turtle.showturtle()
turtle.pencolor(_DRAW_PATH)
# Move to star
turtle.penup()
turtle.goto(home_x, home_y)
turtle.pendown()
# Draw the path
for pos in positions:
turtle.goto(position_to_turtle(pos))
示例7: main
def main():
"""
Tous les phase du battleship passe par le main()
et il sert de boucle principal car il est appelé à
tous les 0.5 secondes
"""
if i.phase == "PlaceShip":
i.placeShip()
elif i.phase == "Attack": # Nom fictif
i.attack()
elif i.phase == "win":
print('Vous avez gagné!')
turtle.goto(0,0)
turtle.pencolor('black')
turtle.write('Vous avez gagné!',align="center",font=("Arial",70, "normal"))
i.phase = "exit"
elif i.phase == "lose":
print('Vous avez perdu!')
turtle.goto(0,0)
turtle.pencolor('black')
turtle.write('Vous avez perdu!',align="center",font=("Arial",70, "normal"))
i.phase = "exit"
elif i.phase == "exit":
turtle.exitonclick()
return None
else:
print('out')
turtle.ontimer(main,500)
示例8: alpha_beta_helper
def alpha_beta_helper():
global state, root, alpha_time
initialize()
print("PLEASE WAIT!!!")
root = TreeNode(-1000)
time1 = time.time()
alpha_beta(root, 1, state)
init_screen()
drawLine()
drawGrid()
drawColumns()
drawRows()
caliberate()
col = root.ans
row = -1
turtle.onscreenclick(goto)
for i in range(4):
if state[i][col] == 0:
row = i
break
state[row][col] = 1
drawDot(row, col, 1)
var = (int)(input("Enter 1 to continue playing or 0 to stop."))
time2 = time.time()
alpha_time = time2-time1
if(var == 1):
turtle.clear()
turtle.goto(0, 0)
turtle.penup()
turtle.right(270)
alpha_beta_helper()
else:
write_analysis(3)
示例9: draw_tree
def draw_tree(x,y):
startPosX = x
startPosY = y
turtle.setpos(x,y)
turtle.fillcolor("green")
turtle.begin_fill()
for i in range(0,4):
x -=40
y -=80
turtle.goto(x,y)
coords.append(turtle.pos())
x += 20
turtle.goto(x,y)
bottomCorner = turtle.pos()
x = startPosX
y = startPosY
turtle.setpos(x,y)
for i in range(0,4):
x +=40
y -=80
turtle.goto(x,y)
coords.append(turtle.pos())
x -= 20
turtle.goto(x,y)
turtle.goto(bottomCorner)
turtle.end_fill()
示例10: roach
def roach(turt):
#make moves a global variable
global moves
turt.pencolor(randrange(255),randrange(255),randrange(255))
turtle.up()
turtle.goto(0,0)
turtle.down()
#write the code for roach to go & turn
while True:
moves += 1
turt_heading = randrange(0,361)
turt.left(turt_heading)
turt_length = randrange(0,31)
turt.forward(turt_length)
distance = dist(turt)
#if statement to determine if the roach is outside the circle or inside
#if inside, keep moving
#if outside, stop moving
#return coordinate
if distance >= 200:
break
turt.up()
moves += moves #accummulate total moves
print(moves)
return moves
示例11: drawLine
def drawLine():
turtle.penup()
turtle.goto(-50, 300)
turtle.pendown()
turtle.write("Base Line", font=("Arial", 14, "normal"))
turtle.color("red")
turtle.forward(500)
示例12: hands
def hands( freq=166 ):
"""Draw three hands.
:param freq: Frequency of refresh in milliseconds.
"""
global running
now= datetime.datetime.now()
time= now.time()
h, m, s, ms = time.hour, time.minute, time.second, int(time.microsecond/1000)
# Erase old hands.
while turtle.undobufferentries():
turtle.undo()
# Draw new hands.
hand( h*5+m/60+s/3600, .6*R, 3 )
hand( m+s/60, .8*R, 2 )
hand( s+ms/1000, .9*R, 1 )
# Draw date and time
turtle.penup(); turtle.home()
turtle.goto( 0, -120 ); turtle.write( now.strftime("%b %d %H:%M:%S"), align="center", font=("Helvetica", 24, "normal") )
# Reschedule hands function
if running:
# Reset timer for next second (including microsecond tweak)
turtle.ontimer( hands, freq-(ms%freq) )
示例13: draw_circle
def draw_circle(x,y,r,t):
t.pu()
t.goto(x+r,y)
t.setheading(90)
t.pd()
t.circle(r)
t.pu()
示例14: drawCloud
def drawCloud(words, num = 20):
""" Draws a wordcloud with 20 random words, sized by frequency found in
the WORDS dictionary. """
t.reset()
t.up()
t.hideturtle()
topCounts = sorted([words[word] for word in list(words.keys()) if len(word) > 3])
largest = topCounts[0]
normalized_counts = {}
for item in list(words.keys()):
if len(item) > 3:
newSize = int(float(words[item]) / largest * 24)
normalized_counts[item] = newSize
size = t.screensize()
width_dim = (int(-1 * size[0] / 1.5), int(size[0] / 2))
height_dim = (int(-1 * size[1] / 1.5), int(size[1] / 1.5))
for item in random.sample(list(normalized_counts.keys()), num):
t.goto(random.randint(*width_dim), random.randint(*height_dim))
t.color(random.choice(COLORS))
try:
t.write(item, font = ("Arial", int(normalized_counts[item]), "normal"))
except:
try:
t.write(str(item, errors = 'ignore'), font = ("Arial", int(normalized_counts[item]), "normal"))
except:
pass
示例15: circle
def circle(x,y,size):
turtle.pu()
turtle.goto(x,y)
turtle.pd()
turtle.begin_fill()
turtle.circle(size)
turtle.end_fill()