---
title: "Motion lab: springs you can touch — Akshay Maurya"
url: "https://www.akshaymaurya.com/lab"
description: "Three small interactions with live spring controls: a tap that pops, a card stack you fling, a badge that lands. Each one shows its Flutter code."
---

# Motion lab

Three techniques from my production motion work, rebuilt small enough to play with. Tap, drag and fling them, then move the sliders and feel what changes.

Each one runs on a spring. The Flutter code beside it uses the same three numbers, so what you tune here is what I would ship in your app.

The page is interactive: each exhibit has sliders for stiffness, damping and mass, a slow-motion toggle at 0.25× speed and a reset. The Flutter code below shows the default values; on the page it updates as the sliders move. The interactions are original to this site and are not copies of any client's designs.

## Fig. 1. Claim

A reward token. Tap it, or press and hold. It squashes under the press, pops on release and settles on the spring.

The press drives one value from 0 to 1, read as a squash. The release hands that value to a spring with a velocity that grows with the depth of the press, so the token overshoots into a stretch and settles. The burst is drawn on a canvas, so it costs no layout.

Default spring: stiffness 420, damping 14, mass 1. It settles in about 1000 ms.

```dart
// Fig. 1, Claim. The press squashes the token,
// and the release pops it.
const spring = SpringDescription(
  mass: 1,
  stiffness: 420,
  damping: 14,
);

late final squash =
    AnimationController.unbounded(vsync: this);

void onTapDown(TapDownDetails _) => squash.animateTo(
      1,
      duration: const Duration(milliseconds: 600),
      curve: Curves.easeOut,
    );

void onTapUp(TapUpDetails _) {
  // A deeper press leaves faster, so it pops harder.
  final speed = sqrt(spring.stiffness / spring.mass);
  final kick = -speed * (0.5 + 0.6 * squash.value);
  squash.animateWith(
    SpringSimulation(spring, squash.value, 0, kick),
  );
}
```

## Fig. 2. Fling

A stack of cards. Drag the top one and let go. Past the first or last card it rubber-bands, and you can catch it mid-flight.

The spring starts from the release velocity, so there is no seam between the drag and the animation. The throw is projected forward and the stack snaps to the card nearest that point. Past either end the drag meets rising resistance. A grab or a key press mid-flight starts a new spring from the live position and velocity: it retargets and never restarts.

Default spring: stiffness 260, damping 26, mass 1. It settles in about 600 ms.

```dart
// Fig. 2, Fling. The release velocity goes
// straight into the spring.
const spring = SpringDescription(
  mass: 1,
  stiffness: 260,
  damping: 26,
);

late final offset =
    AnimationController.unbounded(vsync: this);

void onPanEnd(DragEndDetails d) {
  final velocity = -d.velocity.pixelsPerSecond.dx;
  // Project the throw, then snap to the nearest card.
  final projected = offset.value + velocity * 0.499;
  final index =
      (projected / cardWidth).round().clamp(0, cards - 1);
  // Start from the live value and velocity,
  // so a grab mid-flight retargets.
  offset.animateWith(SpringSimulation(
    spring, offset.value, index * cardWidth, velocity,
  ));
}
```

## Fig. 3. Land

A badge that arrives with weight. It winds up, drops, and the overshoot becomes a squash against the floor before it settles.

Three beats in sequence. Anticipation: a short rise against the direction of travel. Overshoot: the drop runs on the spring, and the distance it travels past the floor is drawn as a squash, not as sinking through. Settle: the tail of the same spring.

Default spring: stiffness 320, damping 16, mass 1.4. It settles in about 1100 ms.

```dart
// Fig. 3, Land. Wind up, drop on the spring,
// and draw the overshoot as squash.
const spring = SpringDescription(
  mass: 1.4,
  stiffness: 320,
  damping: 16,
);

late final drop = AnimationController.unbounded(
  vsync: this,
  value: -120,
);

Future<void> land() async {
  await drop.animateTo(
    -132,
    duration: const Duration(milliseconds: 180),
    curve: Curves.easeOut,
  );
  await drop.animateWith(
    SpringSimulation(spring, drop.value, 0, 0),
  );
}

// In build: above the floor the badge travels,
// past it the badge squashes.
// final travel = math.min(drop.value, 0.0);
// final squash = math.max(drop.value, 0.0);
```

## Want this in your app?

A motion audit finds where your app stutters and which animations are worth their weight, then ranks the fixes. Send a short brief by email, or book a 20-minute call.

- Email: akshaymaurya3006@gmail.com with the subject "Motion audit, from the lab: <your app>"
- Book a call: https://calendar.app.google/TFVnHmarrefPJv5V6
- Plans: https://www.hashstudios.in/#pricing
- Reply: replies within 24 hours
