本文整理汇总了Python中turtle.Turtle.position方法的典型用法代码示例。如果您正苦于以下问题:Python Turtle.position方法的具体用法?Python Turtle.position怎么用?Python Turtle.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类turtle.Turtle
的用法示例。
在下文中一共展示了Turtle.position方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: range
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import position [as 别名]
# Set the window background color to black
window.bgcolor("black")
# Make the cursor ink white, the width of the pen 3, the shape a turtle, and
# move at moderate speed
cursor.color("white")
cursor.width(3)
cursor.shape("turtle") # or "circle", "classic", etc.
cursor.speed(5) # 1 - 10
# Draw a square of side length 100 starting from the home position
cursor.home()
for i in range(4):
print cursor.position()
cursor.forward(100)
cursor.right(90)
print cursor.position()
# Move the turtle to (0, 100) without drawing anything,
# then draw a pentagon
cursor.penup()
cursor.sety(100)
print cursor.position()
cursor.pendown()
cursor.color("green")
cursor.circle(50, steps=5) # remove ", steps=5" to make a circle
# Keep the window open until you click to close it
window.exitonclick()
示例2: draw_line
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import position [as 别名]
from turtle import Turtle
def draw_line (t, x1, y1, x2, y2) :
t.up()
t.setx(x1)
t.sety(y1)
t.down()
t.goto(x2, y2)
def draw_curve (t, x1, y1, x2, y2, l) :
if l == 0 :
draw_line(t, x1, y1, x2, y2)
else :
xm = (x1 + x2 + y1 - y2) / 2
ym = (x2 + y1 + y2 - x1) / 2
draw_curve (t, x1, y1, xm, ym, l - 1)
draw_curve (t, xm, ym, x2, y2, l - 1)
print("Draw.py")
t = Turtle()
assert t.isdown()
assert t.pencolor() == "black"
assert t.position() == (0, 0)
t.pencolor("blue")
draw_curve(t, 50, -50, 50, 50, 10)
raw_input()
print("Done.")
示例3: raw_input
# 需要导入模块: from turtle import Turtle [as 别名]
# 或者: from turtle.Turtle import position [as 别名]
# Step 5, ask user: turn right or left?
turn = raw_input("Turn right or left?")
# Step 6, make a turn according to user's answer:
# If turn equals "right", then turn right for 90 degrees;
# Otherwise, turn left for 90 degrees.
# Your code here
# Step 7, after turtle made a turn,
# move forward according to user's answer
distance2 = raw_input("how far?")
distance2 = int(distance2)
nick.forward(distance2)
# Step 8, we are done with all movings,
# now get turtle's current position, and print it out
turtle_pos_x, turtle_pos_y = nick.position()
turtle_pos_x = int(turtle_pos_x)
turtle_pos_y = int(turtle_pos_y)
print "Turtle's position is:", turtle_pos_x, turtle_pos_y
# Step 9, check if turtle found the food:
# Check if turtle x coordinate equals to food x coordinate
# And turtle y corrdinate equals to food y coordinate
# If both are equal, means turtle got the food, and you WIN !!
if (Your code here) and (Your code here):
print "You find the food! You win!"
else:
print "You lose :("