28 lines
791 B
Python
28 lines
791 B
Python
#!/usr/bin/env python3
|
|
"""Generate deterministic v1 little-endian OfflineFixture field payloads."""
|
|
|
|
from pathlib import Path
|
|
import struct
|
|
|
|
|
|
GRID = 16
|
|
ROOT = Path(__file__).resolve().parents[1] / "particle-fixtures"
|
|
|
|
|
|
def velocity(fixture: str, x: int, y: int) -> tuple[float, float]:
|
|
if fixture == "uniform-east":
|
|
return 1.0, 0.0
|
|
if fixture == "uniform-north":
|
|
return 0.0, 1.0
|
|
local_x = (x + 0.5) / GRID - 0.5
|
|
local_y = (y + 0.5) / GRID - 0.5
|
|
return -2.0 * local_y, 2.0 * local_x
|
|
|
|
|
|
for fixture in ("uniform-east", "uniform-north", "vortex"):
|
|
payload = bytearray()
|
|
for y in range(GRID):
|
|
for x in range(GRID):
|
|
payload.extend(struct.pack("<ff", *velocity(fixture, x, y)))
|
|
(ROOT / fixture / "field.f32").write_bytes(payload)
|