From f5e11763a7a028745b13a48ea380d527713c0fcb Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Thu, 12 Mar 2026 18:07:28 -0400 Subject: [PATCH] fix: proportional speed scaling for +/- keys in bounce demo Replace impel()/dampen() calls with proportional 15% velocity scaling. The old impel() had a fixed-kick path for slow spheres that caused 100x speed jumps when a dampened sphere crossed the speed threshold. Co-Authored-By: Claude Opus 4.6 --- userspace/programs/src/bounce.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/userspace/programs/src/bounce.rs b/userspace/programs/src/bounce.rs index 53a2a85f..49d93b84 100644 --- a/userspace/programs/src/bounce.rs +++ b/userspace/programs/src/bounce.rs @@ -432,10 +432,18 @@ fn run_window_loop(win: &mut Window, spheres: &mut [Sphere; NUM_SPHERES]) { Event::KeyPress { ascii, .. } => { match ascii { b'+' | b'=' => { - for sphere in spheres.iter_mut() { sphere.impel(); } + // Scale all velocities up by ~15% + for sphere in spheres.iter_mut() { + sphere.vx = sphere.vx * 23 / 20; + sphere.vy = sphere.vy * 23 / 20; + } } b'-' => { - for sphere in spheres.iter_mut() { sphere.dampen(); } + // Scale all velocities down by ~15% + for sphere in spheres.iter_mut() { + sphere.vx = sphere.vx * 20 / 23; + sphere.vy = sphere.vy * 20 / 23; + } } _ => {} }