aus vid
unknown
python
a year ago
1.6 kB
7
Indexable
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from PIL import Image
import numpy as np
# Load a map of Australia (use an image file of a map)
# You can replace 'australia_map.png' with your map image.
try:
australia_map = Image.open("australia_map.png")
except FileNotFoundError:
print("Please make sure you have a map of Australia saved as 'australia_map.png' in the same directory.")
exit()
# Convert the image to an array for Matplotlib
map_array = np.asarray(australia_map)
# Define the roller coaster path (latitude, longitude as points)
roller_coaster_path = [
(100, 500), (150, 450), (200, 400), (300, 380), (400, 360), # East coast
(450, 300), (500, 250), (550, 200), (600, 150), (700, 100) # Westward
]
# Extract x and y coordinates
x_coords, y_coords = zip(*roller_coaster_path)
# Create the figure and axis
fig, ax = plt.subplots()
ax.imshow(map_array, extent=[0, 800, 0, 600]) # Adjust extents for your map size
roller_coaster, = ax.plot([], [], 'ro-', markersize=8, label="Roller Coaster")
# Initialize the animation
def init():
roller_coaster.set_data([], [])
return roller_coaster,
# Update function for animation
def update(frame):
roller_coaster.set_data(x_coords[:frame], y_coords[:frame])
return roller_coaster,
# Create the animation
ani = animation.FuncAnimation(
fig, update, frames=len(roller_coaster_path)+1,
init_func=init, blit=True, interval=500
)
# Add labels and title
ax.set_title("Roller Coaster Through Australia")
ax.legend()
ax.axis("off")
# Show the animation
plt.show()
Editor is loading...
Leave a Comment