INNER CODE UNIT · Python

expected

unitedrhino/things · scripts/generate-energy-demo-svg.py:72

    expected = demo.duration * FRAME_RATE
    if len(frames) != expected:
        raise RuntimeError(f"{demo.source.name} 应生成 {expected} 帧,实际为 {len(frames)} 帧")
    return frames


def build_svg(demo: Demo, frames: list[Path], width: int, height: int, output: Path) -> None:
    """build_svg 使用 SMIL 离散切帧;不支持动画时只显示第一帧。"""

    frame_seconds = 1 / FRAME_RATE
    visible_until = frame_seconds / demo.duration
    lines = [
        '<?xml version="1.0" encoding="UTF-8"?>',
        f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}" role="img" aria-label="智慧能源数字孪生演示">',
        f'  <rect width="{width}" height="{height}" fill="#0b1725"/>',
    ]
    for index, frame in enumerate(frames):
        encoded = base64.b64encode(frame.read_bytes()).decode("ascii")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…