Skip to content

Commit f964bb7

Browse files
committed
Add fps and boid counters to the duck example
Same as previous commit
1 parent 43c4ac5 commit f964bb7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

crates/processing_pyo3/examples/flocking_duck.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
center = None
162162
extent = 0.0
163163
max_speed = 0.0
164+
boid_count = 0
165+
title_last_time = 0.0
166+
title_last_frame = 0
164167

165168

166169
# Two triangles folded slightly along the nose-tail spine, like a paper
@@ -185,7 +188,7 @@ def boid_geometry(half_width, length, droop):
185188

186189

187190
def setup():
188-
global p, boid, mat, flock_pass, integrate_pass, center, extent, max_speed
191+
global p, boid, mat, flock_pass, integrate_pass, center, extent, max_speed, boid_count
189192

190193
size(900, 700)
191194
mode_3d()
@@ -215,6 +218,8 @@ def setup():
215218
# derived from the mesh's bounding box, so the sketch doesn't care what
216219
# units the model was authored in.
217220
homes = p.buffer(Attribute.position()).read()
221+
boid_count = len(homes)
222+
window_title(f"GPU Flocking Duck — {boid_count:,} boids")
218223
lo = [min(v[i] for v in homes) for i in range(3)]
219224
hi = [max(v[i] for v in homes) for i in range(3)]
220225
center = [(lo[i] + hi[i]) * 0.5 for i in range(3)]
@@ -246,6 +251,15 @@ def setup():
246251

247252

248253
def draw():
254+
global title_last_time, title_last_frame
255+
256+
title_elapsed = elapsed_time - title_last_time
257+
if title_elapsed >= 0.5:
258+
fps = (frame_count - title_last_frame) / title_elapsed
259+
window_title(f"GPU Flocking Duck — {boid_count:,} boids — {fps:.0f} FPS")
260+
title_last_time = elapsed_time
261+
title_last_frame = frame_count
262+
249263
t = elapsed_time * 0.2
250264
r = extent * 1.1
251265
camera_position(center[0] + cos(t) * r, center[1] + extent * 0.35, center[2] + sin(t) * r)

0 commit comments

Comments
 (0)