Skip to content

Commit e01e51a

Browse files
committed
Adding FPS to flocking.py
1 parent e672a02 commit e01e51a

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

crates/processing_pyo3/examples/flocking.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,29 @@
1111

1212
flock = None
1313

14+
title_last_time = 0.0
15+
title_last_frame = 0
16+
boid_count = 150
1417

1518
def setup():
1619
global flock
1720
size(640, 360)
1821
flock = Flock()
1922
# Add an initial set of boids into the system
20-
for i in range(150):
23+
for i in range(boid_count):
2124
flock.add_boid(Boid(width / 2, height / 2))
2225

2326

2427
def draw():
28+
global title_last_time, title_last_frame
29+
30+
title_elapsed = elapsed_time - title_last_time
31+
if title_elapsed >= 0.5:
32+
fps = (frame_count - title_last_frame) / title_elapsed
33+
window_title(f"GPU Flocking Duck — {boid_count:,} boids — {fps:.0f} FPS")
34+
title_last_time = elapsed_time
35+
title_last_frame = frame_count
36+
2537
background(50)
2638
flock.run()
2739

0 commit comments

Comments
 (0)