""" world_clock.py — the human tide. Births, deaths, and the raw velocity of us. There is no live feed of every birth and death on Earth, so — like a world population clock — this MODELS them from published global vital rates and lets them breathe with a gentle diurnal swell. It is honest about being a model, not a measurement. Musically it's a steady, slow-moving velocity: perfect for note density, drone weight, or the brightness/darkness of a track. Emits: /gs/clock/births births per second (~4.3, breathing) /gs/clock/deaths deaths per second (~2.0, breathing) /gs/clock/popvel net population growth per second (births - deaths) /gs/clock/pop running world population estimate """ from __future__ import annotations import argparse import datetime import math import time from pythonosc.udp_client import SimpleUDPClient # published global approximations (mid-2020s) BIRTHS_PER_SEC = 4.3 DEATHS_PER_SEC = 2.0 POP_BASE = 8_200_000_000 # ~mid-2026 POP_BASE_EPOCH = 1_751_328_000 # 2025-07-01 UTC, seconds def diurnal(t_utc: float, amp: float) -> float: """A slow ±amp sway over 24h so the numbers feel alive, not flat.""" frac = (t_utc % 86400) / 86400.0 return 1.0 + amp * math.sin(2 * math.pi * frac) def main(): ap = argparse.ArgumentParser() ap.add_argument("--host", default="127.0.0.1") ap.add_argument("--port", type=int, default=9000) ap.add_argument("--interval", type=float, default=1.0) args = ap.parse_args() client = SimpleUDPClient(args.host, args.port) print("[clock] emitting /gs/clock/births|deaths|popvel|pop every " f"{args.interval:g}s (modelled)") while True: try: t = time.time() births = BIRTHS_PER_SEC * diurnal(t, 0.06) deaths = DEATHS_PER_SEC * diurnal(t + 21600, 0.05) # offset phase popvel = births - deaths pop = POP_BASE + (t - POP_BASE_EPOCH) * (BIRTHS_PER_SEC - DEATHS_PER_SEC) client.send_message("/gs/clock/births", float(births)) client.send_message("/gs/clock/deaths", float(deaths)) client.send_message("/gs/clock/popvel", float(popvel)) client.send_message("/gs/clock/pop", float(pop)) except Exception as e: # noqa print(f"[clock] warn: {e}") time.sleep(args.interval) if __name__ == "__main__": main()