Skip to content

Commit f5e1176

Browse files
ryanbreenclaude
andcommitted
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 <noreply@anthropic.com>
1 parent fe8b224 commit f5e1176

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

userspace/programs/src/bounce.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,10 +432,18 @@ fn run_window_loop(win: &mut Window, spheres: &mut [Sphere; NUM_SPHERES]) {
432432
Event::KeyPress { ascii, .. } => {
433433
match ascii {
434434
b'+' | b'=' => {
435-
for sphere in spheres.iter_mut() { sphere.impel(); }
435+
// Scale all velocities up by ~15%
436+
for sphere in spheres.iter_mut() {
437+
sphere.vx = sphere.vx * 23 / 20;
438+
sphere.vy = sphere.vy * 23 / 20;
439+
}
436440
}
437441
b'-' => {
438-
for sphere in spheres.iter_mut() { sphere.dampen(); }
442+
// Scale all velocities down by ~15%
443+
for sphere in spheres.iter_mut() {
444+
sphere.vx = sphere.vx * 20 / 23;
445+
sphere.vy = sphere.vy * 20 / 23;
446+
}
439447
}
440448
_ => {}
441449
}

0 commit comments

Comments
 (0)