saving animation to file
parent
58023f2918
commit
470223d7de
|
@ -1 +1,2 @@
|
|||
__pycache__
|
||||
__pycache__
|
||||
output
|
24
main.py
24
main.py
|
@ -1,15 +1,26 @@
|
|||
from sim import Environment, CAMSReverseAndSidestepAgent, Direction
|
||||
import time
|
||||
import datetime
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
import os
|
||||
from pathlib import Path
|
||||
from matplotlib.animation import FuncAnimation
|
||||
|
||||
ANIMATION_OUTPUT_DIRECTORY = "./output"
|
||||
STEPS = 1000
|
||||
|
||||
np.random.seed(12345)
|
||||
fig, ax = plt.subplots()
|
||||
env = Environment((100, 100))
|
||||
|
||||
start_time = datetime.datetime.now()
|
||||
start_time_timestamp = start_time.strftime("%Y-%m-%dT%H%M%S%z")
|
||||
saved_animation_filename = "CAMS-replicator-simulation-{}.mp4".format(start_time_timestamp)
|
||||
output_path = os.path.join(ANIMATION_OUTPUT_DIRECTORY, saved_animation_filename)
|
||||
|
||||
if not os.path.exists(ANIMATION_OUTPUT_DIRECTORY):
|
||||
os.makedirs(ANIMATION_OUTPUT_DIRECTORY)
|
||||
|
||||
first_agent = CAMSReverseAndSidestepAgent(
|
||||
environment=env,
|
||||
position=(50,50),
|
||||
|
@ -29,6 +40,13 @@ ani = FuncAnimation(
|
|||
fig=fig,
|
||||
func=update,
|
||||
frames=STEPS,
|
||||
blit=True)
|
||||
blit=True,
|
||||
interval=1000/60,
|
||||
repeat=False
|
||||
)
|
||||
|
||||
plt.show()
|
||||
#plt.show()
|
||||
|
||||
print("Saving animation, this might take some time...")
|
||||
ani.save(output_path, progress_callback=(lambda i, n: print(f'Saving frame {i}/{n}')))
|
||||
print("Animation saved.")
|
Loading…
Reference in New Issue