当前位置: 首页>>代码示例>>Python>>正文


Python Turtle.position方法代码示例

本文整理汇总了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()
开发者ID:WheatonWHALE,项目名称:comp115,代码行数:32,代码来源:15_turtle_examples.py

示例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.")
开发者ID:digitalzombie,项目名称:oopljpl,代码行数:31,代码来源:Draw.py

示例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 :("
开发者ID:bofeng,项目名称:python-tutorial,代码行数:31,代码来源:findfood.py


注:本文中的turtle.Turtle.position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。