shpapps

Lab · Playground

Fling Lab

Throw a card, catch it mid-flight, send it somewhere else while it is still moving. A gesture feels physical when the motion after the finger lifts carries on at the finger's speed. Flip the switches to feel what happens when it does not, slow it all down to watch, then copy the code for Flutter or the web.

  • Fling, catch, retarget
  • Springs and friction
  • Slow motion
  • Flutter and JavaScript
  • Runs in your browser

Playground

Drag it and let go. Or focus it and press an arrow key to flick it.

Send it to, even mid-flight
Let go at
–
Would coast
–
Headed for
–
Settled in
–

Speed over time

A line with no break at let go means the motion took over the finger's speed. Switch off Keep the finger's speed to see it drop to zero.

Feel

Stiffness pulls harder; damping ratio 1 settles with no overshoot, lower bounces. Friction is how fast a coast loses speed: after t seconds it keeps e−friction × t of it.

Code for Corners

The code uses your stiffness, damping ratio and friction, and always keeps the finger's speed and aims where the throw would coast: the switches are there to feel what happens when you don't. The JavaScript is the same math this page runs.

What makes a throw feel right

A spring is a state, not a timeline

An eased animation knows where it should be at each moment of a fixed duration. A spring only knows where it is, how fast it is going and where it is pulled. So you can grab it, or move its target mid-flight, and it carries on from exactly what it was doing: no jump, no restart, no waiting for the old animation to end.

Aim where the throw would land

Friction that keeps e−λt of the speed carries a throw a further v / λ before it stops. Pick the resting place nearest that point, not the one nearest the finger, and a flick goes where it was thrown. Flutter's FrictionSimulation calls that point finalX.

Measure the speed like the platform does

Speed comes from the last 100 ms of pointer samples, and a finger that has not moved for 40 ms counts as stopped, so a throw that ends in a pause lands softly. Those are the windows of Flutter's VelocityTracker; Fling Lab fits a straight line to them and caps the speed at 8000 px/s, Flutter's kMaxFlingVelocity.

Glide's numbers come from one of our apps

Glide starts with the friction our cross-stitch app Floss pans its pattern chart with: a fling counts above 150 px/s, keeps e−4.5t of its speed and stops below 25 px/s. Fling Lab adds the part a chart does not need: past an edge, the coast hands its speed to a spring that brings it back.