1
- import imageio .v2 as imageio
2
1
import numpy as np
3
2
import matplotlib .pyplot as plt
4
3
from PathPlanning .TimeBasedPathPlanning .GridWithDynamicObstacles import (
@@ -45,7 +44,7 @@ def PlotNodePath(grid: Grid, start: Position, goal: Position, path: NodePath):
45
44
'''
46
45
Plot a series of agent paths.
47
46
'''
48
- def PlotNodePaths (grid : Grid , start_and_goals : list [StartAndGoal ], paths : list [NodePath ], save_gif : bool = False ):
47
+ def PlotNodePaths (grid : Grid , start_and_goals : list [StartAndGoal ], paths : list [NodePath ]):
49
48
fig = plt .figure (figsize = (10 , 7 ))
50
49
51
50
ax = fig .add_subplot (
@@ -99,12 +98,7 @@ def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[N
99
98
max_time = max (path .goal_reached_time () for path in paths )
100
99
101
100
# Animation loop
102
- frames = []
103
101
for i in range (0 , max_time + 1 ):
104
- if save_gif :
105
- plt .savefig (f"frame_{ i :03d} .png" ) # Save each frame as an image
106
- frames .append (imageio .imread (f"frame_{ i :03d} .png" ))
107
-
108
102
# Update obstacle positions
109
103
obs_positions = grid .get_obstacle_positions_at_time (i )
110
104
obs_points .set_data (obs_positions [0 ], obs_positions [1 ])
@@ -128,7 +122,4 @@ def PlotNodePaths(grid: Grid, start_and_goals: list[StartAndGoal], paths: list[N
128
122
129
123
plt .pause (0.2 )
130
124
131
- if save_gif :
132
- imageio .mimsave ("path_animation2.gif" , frames , fps = 5 ) # Convert images to GIF
133
-
134
125
plt .show ()
0 commit comments