Выполнил главу 10
This commit is contained in:
parent
15e79411bd
commit
aafa7c09be
BIN
ch10/earth.gif
Normal file
BIN
ch10/earth.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 52 KiB |
BIN
ch10/iss.gif
Normal file
BIN
ch10/iss.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
49
ch10/iss.py
Normal file
49
ch10/iss.py
Normal file
@ -0,0 +1,49 @@
|
||||
import requests, json, turtle
|
||||
|
||||
iss = turtle.Turtle()
|
||||
|
||||
def setup(window):
|
||||
global iss
|
||||
|
||||
window.setup(1000, 500)
|
||||
window.bgpic('earth.gif')
|
||||
window.setworldcoordinates(-180, -90, 180, 90)
|
||||
turtle.register_shape('iss.gif')
|
||||
iss.shape('iss.gif')
|
||||
|
||||
def mov_iss(lat, long):
|
||||
global iss
|
||||
|
||||
iss.penup()
|
||||
iss.goto(lat, long)
|
||||
iss.pendown()
|
||||
|
||||
def track_iss():
|
||||
url = 'http://api.open-notify.org/iss-now.json'
|
||||
|
||||
response = requests.get(url)
|
||||
|
||||
if (response.status_code == 200):
|
||||
response_dictionary = json.loads(response.text)
|
||||
position = response_dictionary['iss_position']
|
||||
# print('Координаты МКС: ', position['longitude'] + ',' + position['latitude'])
|
||||
lat = float(position['latitude'])
|
||||
long = float(position['longitude'])
|
||||
mov_iss(lat, long)
|
||||
else:
|
||||
print('Хьюстон, у нас проблема:', response.status_code)
|
||||
widget = turtle.getcanvas()
|
||||
widget.after(5000, track_iss())
|
||||
|
||||
|
||||
def main():
|
||||
global iss
|
||||
|
||||
screen = turtle.Screen()
|
||||
setup(screen)
|
||||
track_iss()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
turtle.mainloop()
|
Loading…
x
Reference in New Issue
Block a user