使用乌龟重影
Ghosting using turtle
当 运行 我的脚本时,GIF 或绘图标记(均包含在我的代码中)在屏幕中央生成一秒钟,然后移动到指定位置。为什么? penup()
函数不应该解决这个问题吗?
我正在尝试循环我的 GIF,以便它在我的屏幕上更新和跟踪,同时保持我的其他资产静态。这会导致某种刷新问题吗?
我试过 hideturtle()
但这隐藏了我生成的内容,而不是屏幕中央的原始光点。
# Baikonur Cosmodrome
lat = 45.86
lon = 63.31
location = turtle.Turtle()
location.penup()
location.color('yellow')
location.goto(lon, lat)
location.dot(5)
location.hideturtle()
url = 'http://api.open-notify.org/iss-pass.json'
url = url + '?lat=' +str(lat) + '&lon=' + str(lon)
response = urllib.request.urlopen(url)
result = json.loads(response.read())
over = result['response'][1]['risetime']
style = ('Arial', 6, 'bold')
location.write(time.ctime(over), font=style)
turtle.hideturtle()
def Spacestation_Tracking():
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
location = result['iss_position']
lat = float(location['latitude'])
lon = float(location['longitude'])
print ('latitude: ', lat)
print ('longitude: ', lon)
#Draw the map and the ISS ontop of it the ISS will move to the go to coordinates
screen = turtle.Screen()
screen.setup(1980,1020)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('world3.png')
screen.register_shape('iss3.gif')
iss = turtle.Turtle()
iss.shape('iss3.gif')
iss.setheading(90)
iss.penup()
iss.goto(lon, lat)
time.sleep(5)
while True:
Spacestation_Tracking()
在关闭 window 之前没有错误消息,因为目前无法中断程序。我期待一个干净的点出现在给定的坐标处,并且 GIF 移动和刷新而不是每次都回到中心。
我正在 Windows 10 上使用 Python 为 Windows 下载版本 3.7.3
编码
乌龟将在turtle.Turtle()
returns 时立即可见,penup()
晚了一步。我推荐的是:
lat = 45.86
lon = 63.31
location = turtle.Turtle(visible=False)
location.penup()
location.color('yellow')
location.goto(lon, lat)
location.dot(5)
这消除了在 dot()
之后调用 hideturtle()
的需要,因为海龟已经隐藏并且 dot()
方法不需要海龟可见。同样,我建议:
iss = turtle.Turtle(visible=False)
iss.shape('iss3.gif')
iss.penup()
iss.setheading(90)
iss.goto(lon, lat)
iss.showturtle()
隐藏所有海龟配置,最后调用showturtle()
显示成品。
但是,很难确定,因为您的示例代码没有正确缩进,命令如下:
screen = turtle.Screen()
screen.setup(1980,1020)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('world3.png')
screen.register_shape('iss3.gif')
iss = turtle.Turtle()
iss.shape('iss3.gif')
不属于循环,也不属于重复调用的函数。它们应该是您的设置代码的一部分,并且只调用 一次。
当 运行 我的脚本时,GIF 或绘图标记(均包含在我的代码中)在屏幕中央生成一秒钟,然后移动到指定位置。为什么? penup()
函数不应该解决这个问题吗?
我正在尝试循环我的 GIF,以便它在我的屏幕上更新和跟踪,同时保持我的其他资产静态。这会导致某种刷新问题吗?
我试过 hideturtle()
但这隐藏了我生成的内容,而不是屏幕中央的原始光点。
# Baikonur Cosmodrome
lat = 45.86
lon = 63.31
location = turtle.Turtle()
location.penup()
location.color('yellow')
location.goto(lon, lat)
location.dot(5)
location.hideturtle()
url = 'http://api.open-notify.org/iss-pass.json'
url = url + '?lat=' +str(lat) + '&lon=' + str(lon)
response = urllib.request.urlopen(url)
result = json.loads(response.read())
over = result['response'][1]['risetime']
style = ('Arial', 6, 'bold')
location.write(time.ctime(over), font=style)
turtle.hideturtle()
def Spacestation_Tracking():
url = 'http://api.open-notify.org/iss-now.json'
response = urllib.request.urlopen(url)
result = json.loads(response.read())
location = result['iss_position']
lat = float(location['latitude'])
lon = float(location['longitude'])
print ('latitude: ', lat)
print ('longitude: ', lon)
#Draw the map and the ISS ontop of it the ISS will move to the go to coordinates
screen = turtle.Screen()
screen.setup(1980,1020)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('world3.png')
screen.register_shape('iss3.gif')
iss = turtle.Turtle()
iss.shape('iss3.gif')
iss.setheading(90)
iss.penup()
iss.goto(lon, lat)
time.sleep(5)
while True:
Spacestation_Tracking()
在关闭 window 之前没有错误消息,因为目前无法中断程序。我期待一个干净的点出现在给定的坐标处,并且 GIF 移动和刷新而不是每次都回到中心。
我正在 Windows 10 上使用 Python 为 Windows 下载版本 3.7.3
编码乌龟将在turtle.Turtle()
returns 时立即可见,penup()
晚了一步。我推荐的是:
lat = 45.86
lon = 63.31
location = turtle.Turtle(visible=False)
location.penup()
location.color('yellow')
location.goto(lon, lat)
location.dot(5)
这消除了在 dot()
之后调用 hideturtle()
的需要,因为海龟已经隐藏并且 dot()
方法不需要海龟可见。同样,我建议:
iss = turtle.Turtle(visible=False)
iss.shape('iss3.gif')
iss.penup()
iss.setheading(90)
iss.goto(lon, lat)
iss.showturtle()
隐藏所有海龟配置,最后调用showturtle()
显示成品。
但是,很难确定,因为您的示例代码没有正确缩进,命令如下:
screen = turtle.Screen()
screen.setup(1980,1020)
screen.setworldcoordinates(-180, -90, 180, 90)
screen.bgpic('world3.png')
screen.register_shape('iss3.gif')
iss = turtle.Turtle()
iss.shape('iss3.gif')
不属于循环,也不属于重复调用的函数。它们应该是您的设置代码的一部分,并且只调用 一次。