← Blog

Crochet Pattern Generator

Draw a silhouette, get row-by-row crochet instructions for amigurumi

Amigurumi are small stuffed figures made by crocheting in the round. You start with a magic ring at the bottom, increase stitches each row to widen the shape, then decrease back down to close it off. The pattern for any given shape is just a list of stitch counts per row. If you know the profile you want (say, a sphere, or a pear, or a mushroom), the math to get those stitch counts is mechanical. So why not draw the profile and let the computer figure out the pattern?

Hands crocheting with a hook and yarn
Crocheting. The pattern generator converts 2D profile drawings into row-by-row stitch instructions. Wikimedia Commons

That's what this tool does. You draw one side of your desired shape on a canvas. The app treats that drawing as a surface of revolution, rotating it around the vertical axis to produce a 3D solid. Then it samples the radius at each row height and converts those radii into stitch counts, respecting the physical constraints of crochet.

From drawing to stitches

The drawn profile gets smoothed into a B-spline curve so that minor hand tremors don't produce jagged radius changes between rows. The algorithm samples the curve at fixed height intervals, one per row. At each sample point, it computes the circumference of the corresponding circle and divides by the stitch gauge (which is configurable based on your yarn and hook size) to get the number of stitches for that row.

The tricky part is enforcing crochet constraints. In real life, you can at most double the stitch count from one row to the next (by doing an increase in every stitch). You can at most halve it (by doing a decrease in every stitch). If the drawn profile demands a faster radius change than these limits allow, the algorithm clamps the stitch count and the actual shape will deviate slightly from the drawing. This is honest: the pattern won't promise a shape the yarn can't deliver.

Within each row, increases and decreases need to be distributed evenly around the circle to avoid lumps. If row 5 has 12 stitches and row 6 needs 18, that's 6 increases spread across 12 positions. The algorithm spaces them as uniformly as possible so the fabric grows evenly.

The output

The generated pattern uses standard crochet notation. Each row specifies the stitch type (single crochet, increase, decrease) and the repeat count. The pattern starts with a magic ring of 6 single crochet stitches, because that's the conventional starting point for amigurumi worked in the round. It ends by closing down to somewhere between 6 and 15 stitches, at which point you stuff the figure and sew the opening shut.

A 3D preview shows the rotated shape as you draw, so you can see what the finished amigurumi will look like before generating the pattern. The pattern is exportable as plain text or JSON.

Implementation

The pattern generation runs in Rust compiled to WebAssembly. Three Rust crates handle the pipeline: type definitions, the core algorithm (B-spline interpolation, sampling, constraint enforcement, stitch distribution), and WASM bindings via wasm-pack. The frontend is React with TypeScript, using Canvas for the drawing interface and the 3D preview. WASM computation runs in a Web Worker so the UI stays responsive while the pattern is being generated. Vite handles the dev server and build.