-
Notifications
You must be signed in to change notification settings - Fork 0
/
irma.py
82 lines (58 loc) · 2.62 KB
/
irma.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import turtle
import csv
def irma_setup():
"""Creates the Turtle and the Screen with the map background
and coordinate system set to match latitude and longitude.
:return: a tuple containing the Turtle and the Screen
DO NOT CHANGE THE CODE IN THIS FUNCTION!
"""
import tkinter
turtle.setup(965, 600) # set size of window to size of map
wn = turtle.Screen()
wn.title("Hurricane Irma")
# kludge to get the map shown as a background image,
# since wn.bgpic does not allow you to position the image
canvas = wn.getcanvas()
turtle.setworldcoordinates(-90, 0, -17.66, 45) # set the coordinate system to match lat/long
map_bg_img = tkinter.PhotoImage(file="images/atlantic-basin.gif")
# additional kludge for positioning the background image
# when setworldcoordinates is used
canvas.create_image(-1175, -580, anchor=tkinter.NW, image=map_bg_img)
t = turtle.Turtle()
wn.register_shape("images/hurricane.gif")
t.shape("images/hurricane.gif")
return (t, wn, map_bg_img)
def irma():
"""Animates the path of hurricane Irma
"""
# Do not change this line
# t is the turtle, and you will not need the other variables
(t, wn, map_bg_img) = irma_setup()
hurricaneFile = "data/irma.csv"
# The line below is a little magical. It opens the file,
# with awareness of any errors that might occur.
with open(hurricaneFile, 'r') as csvfile:
# This line gives you an "iterator" you can use to get each line
# in the file.
pointreader = csv.reader(csvfile)
# You'll need to add some code here, before the loop
# One thing you'll need to figure out how to do is to
# skip the first line of the file (which is the header).
# You might use a boolean variable, or you can
# look into Python's built-in next function
#(https://docs.python.org/3/library/functions.html#next)
# pointreader is an iterator
for row in pointreader:
# row is a list representing each line in the csv file
# Each comma separated element is in its own index position
# This code just prints out the date and time elements of each
# row in the file.
# Make sure you understand what is happening here.
# Then, you'll need to change this code
print("Date:", row[0], "Time:", row[1])
# Hack to make sure a reference to the background image stays around
# Do not remove or change this line
return map_bg_img
# Feel free to add "helper" functions here
if __name__ == "__main__":
bg=irma()