Short on time? Jump to the examples and the skill file at the end.
So, winter's coming, and I got asked to make it snow on the world map in our mobile app. Cute little feature. I figured I'd ask my AI agent, tweak a couple of numbers and move on.
The snow showed up in about a minute. And it looked... wrong. Flakes bunched up in little clumps, the whole sky swayed left and right like one big curtain, and flakes faded out and popped right back in on the same spot. It took me a while to put my finger on why it bugged me so much.
Then it clicked. This is the snow on basically every website: random x, random y, fall, jump back to the top. Everyone writes it that way, so of course the AI does too.
I had a nagging feeling that some math from my college classes could fix it, so I went after the problems one at a time. Every demo below can be dragged, so go ahead and play with them.
First thing that bugged me was the clumping. Turns out that's just what Math.random() does. Real randomness has clumps and holes, and our eyes read them as mistakes.
The fix even has a cool name: Poisson-disk sampling. You still drop flakes at random, but no two are allowed closer than a minimum gap. Drag the line and check out the circled pair.
Way better. But the big flakes still sat side by side and looked like blobs, so I made the gap grow with size:
gap = base + extra × (radiusA + radiusB)
The spacing was finally right, but every flake vanished at the same height, and the whole thing felt like a flat sticker on the screen. So I gave each size its own fade line. Small flakes disappear high up, big ones hang around longer, and suddenly there's a foreground and a background. You can move the lines for whatever you're dropping: light snow melts near the top, ash makes it all the way down.
This one drove me nuts. Fading out and back in on the same spot is a shortcut for looping, and once you notice it, you can't unsee it. The fix is almost boring: a flake that fades stays gone. It keeps falling where you can't see it and only comes back from the top.
This is where college math finally paid off. Each flake sways on a sine wave:
`x = homeX + amp × sin(2π × t / period + phase)`
If every flake shares the same `phase`, the whole sky swings like it's hanging from one string. Give each flake its own random phase and they all drift on their own little schedule.
Five small rules, and the snow finally looked like snow. That's where I should have stopped. Instead I started messing with the numbers. Make the flakes bigger, slower and petal shaped and you get cherry blossoms. Flip the speed negative and you get embers floating up from a fire. It's the same five rules every time, which still kind of delights me.
I don't want to figure all of this out again next winter, so I wrote it down for future me. The five rules, the math and these presets are all in one file: SKILL.md. With it loaded, my AI agent starts from these rules instead of plain random. If someone's about to ask you for snow this December (they will), hand it to your agent first.
And if Poisson-disk sampling got you curious, Jason Davies' interactive explainer is a beautiful rabbit hole.