capture.pyΒΆ

Part of Clear Code Zelda.

 1#!/usr/bin/env python3
 2"""Capture headless screenshots at frames 30, 60, 120 for review.
 3
 4Run from the repo root:
 5    uv run python examples/ports/clear_code_zelda/capture.py
 6"""
 7
 8from __future__ import annotations
 9
10import sys
11from pathlib import Path
12
13_PORT_DIR = Path(__file__).resolve().parent
14if str(_PORT_DIR) not in sys.path:
15    sys.path.insert(0, str(_PORT_DIR))
16
17from main import ZeldaRoot  # noqa: E402
18from settings import HEIGHT, WIDTH  # noqa: E402
19
20from simvx.graphics import App, save_png  # noqa: E402
21
22
23def main():
24    out = _PORT_DIR / "screenshots"
25    out.mkdir(exist_ok=True)
26    targets = [30, 60, 120]
27    app = App(width=WIDTH, height=HEIGHT, title="Zelda capture", visible=False)
28    frames = app.run_headless(ZeldaRoot(show_menu=False), frames=max(targets) + 1, capture_frames=targets)
29    for idx, frame in zip(targets, frames, strict=False):
30        path = out / f"frame_{idx:03d}.png"
31        save_png(frame, str(path))
32        print(f"saved {path}  shape={frame.shape}")
33
34
35if __name__ == "__main__":
36    main()