Damped spring physics + Newtonian projectile sim
Pure-math animation engine. Damped harmonic oscillators (Ryan-Juckett) for smooth scroll / overshoot, Newtonian projectile sim for arcs and particle effects. No terminal dependency.
composer require sugarcraft/honey-bounce
use SugarCraft\Bounce\{Spring, Projectile, Point, Vector};
$spring = new Spring(
deltaTime: Spring::fps(60),
angularFrequency: 6.0,
dampingRatio: 1.0, // critical
);
$pos = 0.0; $vel = 0.0; $target = 100.0;
for ($f = 0; $f < 60; $f++) {
[$pos, $vel] = $spring->update($pos, $vel, $target);
}
$ball = Projectile::new(
deltaTime: Spring::fps(60),
position: Point::zero(),
velocity: new Vector(5.0, -10.0),
acceleration: Projectile::gravity(),
);
for ($i = 0; $i < 60; $i++) {
$ball = $ball->update();
}
dampingRatio < 1 oscillates, = 1 critical (no overshoot, fastest), > 1 over-damped.Projectile::gravity() + terminalGravity() helpers.Spring::fps(60) returns 1/60 deltaTime. Pair with a 60Hz loop for smooth animation.$pos and $vel in, gets the next pair out.ext-pcntl, nothing. Drop into a job worker if you need physics in a non-TUI.| Class | Method | Description |
|---|---|---|
| Spring | new(deltaTime, angularFrequency, dampingRatio) | Create a spring physics instance |
| Spring | update(pos, vel, target) | Step the spring simulation |
| Spring | fps($fps) | Create deltaTime for given FPS |
| Projectile | new(deltaTime, position, velocity, acceleration) | Create a projectile |
| Projectile | update() | Step the projectile simulation |
| Projectile | gravity() | Standard gravity acceleration |
| Point | zero() | Create point at origin |
| Vector | new(x, y) | Create a 2D vector |
VHS-recorded GIFs of every example shipped with the library. Regenerated automatically on every push that touches the source.