Tió de Nadal
The Catalan Christmas log, rebuilt as a canvas toy. Whack it with the stick and it squashes, goes red with effort, dances to the song and poops presents.
In Catalonia the presents don’t come down the chimney. They come out of a log. Out of the back end of a log, to be precise, after a room full of kids has hit it with sticks and sung at it. It’s called the tió de Nadal, and every December I’m reminded that this is not a normal thing to explain to people.
So I built one. It plays by itself until you touch it, then the stick is yours.
Fes cagar el tió
// one frame of the squash spring
squashV += -squash * 0.28; // pull back to rest
squashV *= 0.76; // lose a bit each frame
squash += squashV;
// scale from the floor line,
// so it squashes into the ground
ctx.translate(0, FLOOR);
ctx.scale(1 + 0.07 * squash, 1 - 0.09 * squash);
ctx.translate(0, -FLOOR);
So what is a tió
It’s a log with a painted face, a red barretina (the Catalan cap) and stick legs. From early December you feed it every night and tuck a blanket over it so it doesn’t get cold. A pet, basically. A wooden one.
On Christmas Eve or Christmas Day the kids leave the room while the grown-ups “get things ready”, come back, hit it with sticks and sing a song that politely asks it to poop. Under the blanket: turrons, neules, sweets. Never fruit. You feed it fruit, it pays you in turrons. Fair trade.
Taking it apart
It’s one <canvas> and vanilla JS, no images. Pick a part to see it on its own, with the few lines that draw it.
The one rule I kept relearning on the barretina: where two béziers meet, keep the control points either side of the joint in a straight line. If you don’t, you get a tiny kink, and at 3x zoom it looks awful.
Making it feel alive
A still drawing doesn’t need any of this. These three bits are what make it feel like you’re hitting something.
How hard you hit. There’s no cursor ring, the stick is the pointer. Strength comes from how fast you were moving just before the click, and it scales the squash, the cap’s whiplash, the chips and the shake. Touch and keyboard have no swing to read, so they land a medium hit.
const v = Math.hypot(b.x - a.x, b.y - a.y) / dt; // px/ms, last 120ms
const strength = clamp(0.15 + v / 2.4, 0.15, 1); // tap... whack
Pushing. Before it gives, it strains for a second: red face, clenched teeth, a sweat drop. It’s the squash spring from the first demo with its resting point moved down, then a kick the other way so it stretches as it lets go.
squashV += -(squash - 0.32 * strain) * 0.28;
// ...and on release
squashV -= 0.9;
The dance. On every word of the song it dips toward the floor. Half a sine jolted at the top of every beat. 1 - cos leaves and comes back with zero speed, and the legs are drawn from the floor up to the body, so the feet never move.
const k = Math.min(1, (now - beatAt) / 380);
const dip = (1 - Math.cos(k * Math.PI * 2)) / 2 * 6;
With reduced motion on, it doesn’t play by itself, nothing shakes, trembles or dances, and the words light up without the hop. Tab to it and Space hits it.