-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgif_generator.py
More file actions
58 lines (46 loc) · 1.66 KB
/
gif_generator.py
File metadata and controls
58 lines (46 loc) · 1.66 KB
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
import os
import shutil
import imageio.v2 as imageio
def generate_gif(frames_dir, output_path,
explore_duration=0.1, final_duration=1.0):
"""
Combine all PNG frames into a GIF.
Last frame stays visible for `final_duration` seconds.
"""
frame_files = sorted([
os.path.join(frames_dir, f)
for f in os.listdir(frames_dir)
if f.endswith('.png')
])
if not frame_files:
print('[gif_generator] No frames found, skipping GIF.')
return
images = [imageio.imread(f) for f in frame_files]
durations = [explore_duration * 1000] * len(frame_files)
durations[-1] = final_duration * 1000 # linger on last frame
imageio.mimsave(output_path, images, duration=durations, loop=0)
print(f'[gif_generator] GIF saved → {output_path}')
def save_screenshots(frames_dir, screenshots_dir):
"""
Pick 3 representative frames:
01_initial – first frame (empty grid)
02_exploring – middle frame (mid-exploration)
03_final – last frame (path shown)
"""
frame_files = sorted([
f for f in os.listdir(frames_dir) if f.endswith('.png')
])
if not frame_files:
return
os.makedirs(screenshots_dir, exist_ok=True)
picks = {
'01_initial.png': frame_files[0],
'02_exploring.png': frame_files[len(frame_files) // 2],
'03_final.png': frame_files[-1],
}
for name, src_file in picks.items():
shutil.copy(
os.path.join(frames_dir, src_file),
os.path.join(screenshots_dir, name),
)
print(f'[gif_generator] Screenshots saved → {screenshots_dir}/')