# Morphs without spikes

> Most icon morphs look generated for the same few reasons: points paired by accident, moved in straight lines, and corners that snap in. Pair by shape, move strokes whole, and round the corners halfway.

Source: https://cesarvenzac.com/blog/morphs-without-spikes

By César Venzac, published 2026-10-15.

An icon that turns into another one is a small thing to get right and an easy thing to get wrong. The two ends are always fine: they're the icons, drawn by someone who cared. What gives a morph away is the frames in between, which nobody draws and few people look at one by one. That's where the spikes are.

[Icon morphs](https://cesarvenzac.com/lab/icon-morphs) in the Lab plays seven changes three ways at once: in the order the paths were written, as most libraries do; evenly resampled, as flubber does; and softly, the way this post describes. Its Trace switch lays every frame over the others, which is the quickest way to see a morph for what it is.

*Live example on the page: Icon morphs. The same change, three ways, on one clock.* Its source:

```tsx
// A stroke is moved as a whole: where it is, how big it is and which way it
// faces are interpolated apart from its shape. A plus turns into an x; it
// doesn't shrink through the middle, as points moving in straight lines do.
const size = Math.exp(lerp(Math.log(fromSize), Math.log(toSize), t));
const centre = lerpVec(fromCentre, toCentre, t);
const points = fromShape.map((p, i) => {
  const [x, y] = rotate(lerpVec(p, toShape[i], t), turn * t);
  return [centre[0] + size * x, centre[1] + size * y];
});

// Then it's softened along its length: a Gaussian blur over its points that
// peaks halfway and is gone at either end. Corners appear rounded and tighten
// as they arrive, instead of snapping in as kinks.
const soft = soften(points, closed, SOFTEST * Math.sin(Math.PI * t));

// Drawn as a few cubics through anchors chosen once for the whole morph (every
// corner, then as few as keep each frame within 0.04 of its points), sharp only
// at an end's own corners, near that end.
const ease = (i) => 1 - Math.max(cornerFrom[i] ? (1 - t) ** 3 : 0, cornerTo[i] ? t ** 3 : 0);
const nodes = nodesThrough({ points: soft, ease }, closed, anchors);
path.setAttribute("d", nodesData(nodes, closed));
```

## Where the spikes come from

Three things, mostly. The first is pairing by accident. A morph has to decide which point of one icon becomes which point of the other, and the cheapest answer is the order the paths happen to be written in. Nothing in that order says which parts look alike, so a stroke can become any other, and shapes fold through each other on the way.

The second is moving every point in a straight line. That's right for a point that slides, and wrong for one on a stroke that turns: a bar turning into the arm of an x should sweep round, and its points, each taking the short cut, cut across the arc instead, so the bar shrinks as it turns and grows back.

The third is the one that reads as spiky. A corner the second icon has isn't in the first, and moving points in straight lines makes it appear the only way it can, as a kink, sharp from the first frame and only its angle changing. The eye reads a sharp corner as a thing, and a thing that pops in is a glitch. Two smaller tells come with it: drawing the frames as polygons, and strokes with no partner shrinking to a dot that vanishes on the last frame.

*Live example on the page: The spikes, measured. The sharpest bend in every frame, from one icon to the other, each way.* Its source:

```tsx
// How spiky a frame is, measured: the most its outline's way out of a point
// differs from its way in, each over half a unit. A smooth curve bends a little,
// a rounded corner more, and a kink, turning all at once, by its whole angle.
function sharpestBend(d: string): number {
  let sharpest = 0;
  const reach = Math.round(0.5 / STEP); // half a unit either side
  for (const path of parsePath(d)) {
    const traced = outline(path, STEP);
    const length = outlineLength(traced);
    if (length < 1.5) continue; // a dot gathering away is small, not sharp
    // Evenly spaced, so so many points either side is so much outline either side.
    const { points, closed } = resample(traced, Math.round(length / STEP));
    points.forEach((p, k) => {
      const before = closed ? points.at(k - reach) : points[k - reach];
      const after = closed ? points[(k + reach) % points.length] : points[k + reach];
      if (before && after) sharpest = Math.max(sharpest, angle(sub(p, before), sub(after, p)));
    });
  }
  return (sharpest * 180) / Math.PI;
}

// Every frame of a morph, each way: the chart's three lines.
const bends = Array.from({ length: 33 }, (_, k) =>
  Math.max(0, ...morph.at(k / 32).filter((s) => s.width >= 0.5).map((s) => sharpestBend(s.d))),
);
```

## Pair by shape

Lay each stroke out as evenly spaced points, and keep its corners among them exactly. Then, for each pair of strokes, try every starting point and both directions, and score each by how alike the two shapes are once position, size and turn are set aside, with a little extra for turning further. The pairing of the strokes themselves works the same way across the whole icon, and turns that disagree cost more, so the two strokes of a plus pair with the two of an x so that they turn together, the plus turning into the x as one piece.

*Live example on the page: Where a stroke starts. The same stroke started from eight places round it, each scored by how unlike the shapes it pairs are.* Its source:

```tsx
// A closed stroke's points have no first. Try every start round it, both ways,
// and keep the one whose shapes are most alike, with a little extra for
// turning further: of two equal fits, the shorter turn.
let best = null;
for (const candidate of [to, [...to].reverse()]) {
  for (let shift = 0; shift < count; shift++) {
    const started = rolled(candidate, shift);
    const { residual, turn } = shapeFit(from, started, turning);
    const score = residual + TURN_WEIGHT * turn * turn;
    if (!best || score < best.score) best = { to: started, turn, score };
  }
}

// How unlike two shapes are, paired point to point: both centred and sized
// alike, one turned to lie best on the other. What's left is 2 - 2 x their
// correlation: 0 for the same shape, up to 4 for opposites.
function shapeFit(p: Vec[], q: Vec[], turning: boolean) {
  const [cp, cq] = [centroid(p), centroid(q)];
  let dot = 0, cross = 0, sp = 0, sq = 0;
  for (let k = 0; k < p.length; k++) {
    const [px, py] = [p[k][0] - cp[0], p[k][1] - cp[1]];
    const [qx, qy] = [q[k][0] - cq[0], q[k][1] - cq[1]];
    dot += px * qx + py * qy;
    cross += px * qy - py * qx;
    sp += px * px + py * py;
    sq += qx * qx + qy * qy;
  }
  const scale = Math.sqrt(sp * sq);
  if (!turning) return { turn: 0, residual: 2 - (2 * dot) / scale };
  return { turn: Math.atan2(cross, dot), residual: 2 - (2 * Math.hypot(dot, cross)) / scale };
}
```

## Move strokes whole

Instead of moving points, move strokes. Each has a place, a size and, if it's drawn out like a bar, a way it faces. Interpolate those on their own (the size by ratio, so it doesn't sag halfway), and blend only what's left of the shape point by point:

`morph.ts`:

```typescript
const size = Math.exp(lerp(Math.log(fromSize), Math.log(toSize), t));
const centre = lerpVec(fromCentre, toCentre, t);
const points = fromShape.map((p, i) => {
  const [x, y] = rotate(lerpVec(p, toShape[i], t), turn * t);
  return [centre[0] + size * x, centre[1] + size * y];
});
```

Only drawn-out strokes turn. A round shape, a heart or a star, has no way it faces, and fitting it a turn anyway spins the whole icon for no reason. Stroke by stroke, a bar turns and a blob doesn't.

*Live example on the page: Strokes moved whole. Point by point, the chevron comes out a third shorter halfway round.* Its source:

```tsx
// A stroke's place, size and turn, set apart from its shape: its centre, its
// size (how far its points sit from the centre, on average), and the turn that
// lays one shape best on the other (from shapeFit).
const centre = (points: Vec[]) => scale(points.reduce(add), 1 / points.length);
const size = (points: Vec[], c: Vec) =>
  Math.sqrt(points.reduce((sum, p) => sum + distance(p, c) ** 2, 0) / points.length);

const [cf, ct] = [centre(from), centre(to)];
const [sf, st] = [size(from, cf), size(to, ct)];
const shapeFrom = from.map((p) => scale(sub(p, cf), 1 / sf));
const shapeTo = to.map((p) => rotate(scale(sub(p, ct), 1 / st), -turn));

// Each frame moves those on their own, the size by ratio so it doesn't sag
// halfway, and blends only what's left of the shape, point by point.
function frame(t: number) {
  const s = Math.exp(lerp(Math.log(sf), Math.log(st), t));
  const c = lerpVec(cf, ct, t);
  return shapeFrom.map((p, i) => add(c, scale(rotate(lerpVec(p, shapeTo[i], t), turn * t), s)));
}

// Only a stroke drawn out at both ends turns: a bar or a chevron, not a heart.
// How drawn out: its spread along its long axis over its spread across it.
const turning = Math.min(elongation(from), elongation(to)) > 3;
```

## Round the corners halfway

This is the part that makes it look soft. Blur each stroke's points along its length, with a Gaussian whose width follows the morph: nothing at either end, about a unit (on Lucide's 24-unit grid) halfway. A corner the next icon needs now arrives rounded and tightens as it lands, and one the first icon had loosens before it goes. Mirror an open stroke's points through its ends before blurring, and its straight lines stay straight and its ends stay put.

*Live example on the page: Corners rounded halfway. As a kink, the corner is sharp from the first frame; rounded, it tightens as it lands.* Its source:

```tsx
// A stroke's points blurred along its length by a Gaussian sigma units wide,
// sigma = SOFTEST * sin(PI * t): nothing at either end, most halfway. A corner
// the next icon needs arrives rounded and tightens as it lands.
function soften(points: Vec[], closed: boolean, sigma: number): Vec[] {
  const n = points.length;
  if (sigma <= 0) return points;
  const spacing = strokeLength(points, closed) / (closed ? n : n - 1);
  const reach = Math.min(Math.ceil((3 * sigma) / spacing), closed ? n >> 1 : n - 1);
  const weights = Array.from({ length: reach + 1 }, (_, j) =>
    Math.exp(-((j * spacing) ** 2) / (2 * sigma * sigma)),
  );
  // Past an open stroke's end, its points mirrored through the end: straight
  // lines stay straight, and the ends stay where they are.
  const at = (k: number): Vec => {
    if (closed) return points[((k % n) + n) % n];
    if (k < 0) return sub(scale(points[0], 2), points[-k]);
    if (k >= n) return sub(scale(points[n - 1], 2), points[2 * (n - 1) - k]);
    return points[k];
  };
  return points.map((_, k) => {
    let sum: Vec = [0, 0];
    let total = 0;
    for (let j = -reach; j <= reach; j++) {
      sum = add(sum, scale(at(k + j), weights[Math.abs(j)]));
      total += weights[Math.abs(j)];
    }
    return scale(sum, 1 / total);
  });
}
```

Then draw the points as one smooth curve, not a polygon, sharp only at an icon's own corners and only near that icon, so the last frames close in on the real thing instead of jumping to it. A stroke with no partner gathers into a dot and the dot shrinks away, so nothing vanishes on the last frame.

*Live example on the page: Points drawn as curves. The same points as a polygon, and as the few cubics an editor would draw.* Its source:

```tsx
// Anchors are chosen once for the whole morph: every corner either icon has,
// then, from each anchor, the farthest point a single cubic still reaches with
// every frame within TOLERANCE (0.04 units) of its points. So the anchors glide
// from frame to frame instead of popping in and out.
function chooseAnchors(frames: Frame[], forced: boolean[]): number[] {
  const fits = (from: number, to: number) =>
    frames.every((frame) => fitBetween(frame, from, to).error <= TOLERANCE);
  const anchors = [0];
  for (let current = 0; current < last; ) {
    let next = current + 1;
    // As far as it still fits, out to the next corner at most.
    while (next < limitFrom(current, forced) && fits(current, next + 1)) next++;
    anchors.push((current = next));
  }
  return anchors;
}

// Between two anchors, one cubic leaving and arriving along the stroke: its
// handles' lengths fitted by least squares (Schneider's method), then each
// point's place along the curve refined by Newton's method and fitted again.
// At a corner of an end, the two sides' own directions, near that end only:
const ease = (i: number) =>
  1 - Math.max(cornerFrom[i] ? (1 - t) ** 3 : 0, cornerTo[i] ? t ** 3 : 0);

// Drawn as an editor shows it: a C where a side has handles, an L where neither does.
path.setAttribute("d", nodesData(nodesThrough({ points, ease }, closed, anchors), closed));
```

> **Note:** At 0 and 1, draw the icons themselves, not the morph's version of them. A morph is for the frames in between; the ends should be exactly what was designed.

## When to bother

Matching costs a few milliseconds once per pair of icons, and each frame after that is a few thousand points, which is nothing. The cost is attention, and the motion rule that runs this site applies: how often will it be seen? An icon swapped on every hover should crossfade, quickly, and does here. A morph earns its place where an icon changes what it means, play to pause, copy to check, menu to close, a few times a visit. There, it's worth doing well.
