Graphic patterns in knitting are composed of relatively large pixels, which create a picture when seen from a distance, while on close viewing the image falls apart into its constituent stitches. Such imagery is constrained by the nature of knitted material, and is a challenge to create. All styles of multi-colored knitting are thicker and warmer than one-colored knits. The extra thickness occurs because a separate yarn is used for each color. While knitting with the active yarn, the other yarns are hidden on the reverse and referred to as floats. If the floats are left too long the material is likely to catch and rip, which is unpractical. A reasonable thickness and durability require that not more than two yarns are used in the same row and same-color sequences are limited in length, usually between three and five stitches long. The code on this page converts an arbitrary line-drawing or photograph to a constraint-compliant knitting pattern with floats minimized, usable by a programmable Fair-Isle knitting machine or manually. This is done by solving a Constraint Satisfaction Problem (CSP). First a constraint-inconsistent starting pixel assignment is generated by dithering or thresholding. Then a constraint compliant solution is produced by running a search algorithm that makes minimally perceptible modifications to the starting pattern by minimizing pixel flips or adding random noise while preserving gestalt features of the design. Note that the starting image has to be of the desired size, each pixel will be mapped to a knitting stitch, and no scaling is supported in the current version. Individual pixels can be edited after the starting image is loaded and before an optimization is run, and after the optimization is finished.
| Generating a knitting pattern: | ![]() |
| At the back of the fabric: | ![]() |
| An algorithmic top: | ![]() |
| Wim Wenders scarf pattern: | Seen from a distance (Gaussian Blur): | |
![]() | ![]() |
To run open this with Processing sketch and compile as a java application. You will also need a sample image file fog.jpg (the little picture below).
Keyboard Shortcuts:
h - hybrid
m - min conflict
s - GSAT
r - RandomWalk
4 - Regenerate the starting assignment using ordered dithering (matrix size 4)
9 - Rotate the image 90 degrees
8 - save the knitting pattern (each knitted pixel represented by a square)
7 - save the knitting pattern as a source image (each knitted pixel represented by an actual pixel)
0,o - regenerate the starting assignment using ordered dithering (matrix size 3)
t - reload the starting assignment using thresholding
a - turn anchoring on or off
= - zoom in
- - zoom out
g - reload the original using Floyd-Steinberg dithering, increase brightness threshold
f - reload the original using Floyd-Steinberg dithering, decrease brightness threshold
b - reload using Atkinson dithering, darker
d - reload using Atkinson dithering, brighter
l - select a sourse file
Editing the image manually: clicking on the sells will invert them
Please refer to the code (void keyPressed() ) to see more options.