From 43c4ac542f745fce3b1639a47c9c983e9c4b7e91 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20de=20Courville?= Date: Tue, 14 Jul 2026 14:29:49 +0200 Subject: [PATCH 1/2] Add FPS and boid counters to GPU example AI Disclosure: generated with GPT 5.6 Sol. Tested working on my M1 mac running Tahoe. --- crates/processing_pyo3/examples/flocking_gpu.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/processing_pyo3/examples/flocking_gpu.py b/crates/processing_pyo3/examples/flocking_gpu.py index d2f369f..4faaeca 100644 --- a/crates/processing_pyo3/examples/flocking_gpu.py +++ b/crates/processing_pyo3/examples/flocking_gpu.py @@ -156,6 +156,8 @@ mat = None flock_pass = None integrate_pass = None +title_last_time = 0.0 +title_last_frame = 0 # Two triangles folded slightly along the nose-tail spine, like a paper @@ -183,6 +185,7 @@ def setup(): global p, boid, mat, flock_pass, integrate_pass size(900, 700) + window_title(f"GPU Flocking — {BOID_COUNT:,} boids") mode_3d() directional_light((0.95, 0.9, 0.85), 800.0) @@ -226,6 +229,15 @@ def setup(): def draw(): + global title_last_time, title_last_frame + + title_elapsed = elapsed_time - title_last_time + if title_elapsed >= 0.5: + fps = (frame_count - title_last_frame) / title_elapsed + window_title(f"GPU Flocking — {BOID_COUNT:,} boids — {fps:.0f} FPS") + title_last_time = elapsed_time + title_last_frame = frame_count + t = elapsed_time * 0.1 r = BOUND * 2.6 camera_position(cos(t) * r, BOUND * 0.8, sin(t) * r) From f964bb784e76d568605f80c20446c5c20a095730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20de=20Courville?= Date: Tue, 14 Jul 2026 14:38:01 +0200 Subject: [PATCH 2/2] Add fps and boid counters to the duck example Same as previous commit --- crates/processing_pyo3/examples/flocking_duck.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/crates/processing_pyo3/examples/flocking_duck.py b/crates/processing_pyo3/examples/flocking_duck.py index 4ba4dbc..7b5495b 100644 --- a/crates/processing_pyo3/examples/flocking_duck.py +++ b/crates/processing_pyo3/examples/flocking_duck.py @@ -161,6 +161,9 @@ center = None extent = 0.0 max_speed = 0.0 +boid_count = 0 +title_last_time = 0.0 +title_last_frame = 0 # Two triangles folded slightly along the nose-tail spine, like a paper @@ -185,7 +188,7 @@ def boid_geometry(half_width, length, droop): def setup(): - global p, boid, mat, flock_pass, integrate_pass, center, extent, max_speed + global p, boid, mat, flock_pass, integrate_pass, center, extent, max_speed, boid_count size(900, 700) mode_3d() @@ -215,6 +218,8 @@ def setup(): # derived from the mesh's bounding box, so the sketch doesn't care what # units the model was authored in. homes = p.buffer(Attribute.position()).read() + boid_count = len(homes) + window_title(f"GPU Flocking Duck — {boid_count:,} boids") lo = [min(v[i] for v in homes) for i in range(3)] hi = [max(v[i] for v in homes) for i in range(3)] center = [(lo[i] + hi[i]) * 0.5 for i in range(3)] @@ -246,6 +251,15 @@ def setup(): def draw(): + global title_last_time, title_last_frame + + title_elapsed = elapsed_time - title_last_time + if title_elapsed >= 0.5: + fps = (frame_count - title_last_frame) / title_elapsed + window_title(f"GPU Flocking Duck — {boid_count:,} boids — {fps:.0f} FPS") + title_last_time = elapsed_time + title_last_frame = frame_count + t = elapsed_time * 0.2 r = extent * 1.1 camera_position(center[0] + cos(t) * r, center[1] + extent * 0.35, center[2] + sin(t) * r)