From e01e51aa816e30059361abb9ec86a6f04fbfd50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Moon=20Dav=C3=A9?= Date: Thu, 16 Jul 2026 12:02:43 -0400 Subject: [PATCH] Adding FPS to flocking.py --- crates/processing_pyo3/examples/flocking.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/crates/processing_pyo3/examples/flocking.py b/crates/processing_pyo3/examples/flocking.py index b64e4f1..9f65253 100644 --- a/crates/processing_pyo3/examples/flocking.py +++ b/crates/processing_pyo3/examples/flocking.py @@ -11,17 +11,29 @@ flock = None +title_last_time = 0.0 +title_last_frame = 0 +boid_count = 150 def setup(): global flock size(640, 360) flock = Flock() # Add an initial set of boids into the system - for i in range(150): + for i in range(boid_count): flock.add_boid(Boid(width / 2, height / 2)) 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 + background(50) flock.run()