Expressive mascot

Set a mood, trigger a short reaction, and let the face carry the story.

Mood
React

Idle, looking around.

Key CSS & implementation tricks

// x0 y0, c1x c1y, c2x c2y, x1 y1, stroke width
const eye = (x, shape = 'open') => ({
  open:  [x, 65, x, 69, x, 72, x, 76, 10],
  smile: [x - 6, 75, x - 2, 68, x + 2, 68, x + 6, 75, 4.5],
  sleep: [x - 6, 75, x - 2, 79, x + 2, 79, x + 6, 75, 4.5],
}[shape]);
node.setAttribute('d', `M${v[0]} ${v[1]} C${v.slice(2, 8).join(' ')}`);

const source = [...visibleFace];            // what is drawn right now
function frame(now) {
  const t = Math.min(1, (now - started) / 420);
  const eased = t * t * (3 - 2 * t);        // smoothstep
  visibleFace = source.map((v, i) => v + (target[i] - v) * eased);
  drawFace(visibleFace);
  if (t < 1) faceFrame = requestAnimationFrame(frame);
}

.lab-mascot[data-mood="thinking"] .character { animation: ponder 3s ease-in-out infinite; }
.lab-mascot[data-reaction] .character,
.lab-mascot[data-reaction] .face { animation: none; transform: none; }
.lab-mascot[data-reaction="approve"] .character { animation: nod 900ms ease-in-out both; }

function stop() { sequenceToken++; clearTimeout(sequenceTimer); clearTimeout(reactionTimer); }
function sequence() {
  stop();
  const token = sequenceToken;
  function next() {
    if (token !== sequenceToken) return;   // a newer action won
    mood(steps[index++]);
    if (index < steps.length) sequenceTimer = setTimeout(next, 1900);
  }
  next();
}