A little while ago, I posted the Permutating Friends of 3 Scarf Pattern. I also joined the Woolly Thoughts group on Ravelry, and started talking to the great folks there. Woolly Thoughts is one of a kind: combining math and generative knitting, and it turned out that at some point, they too had thought about putting together knitting with permutations. And so, some crazy new thoughts emerged in my head.
I was basically pondering on the idea of scaling and visualizing permutations and partitions: how quickly things scale up in mathematics, (for example, see this link on MathStackExchange), and therefore, how quickly it becomes completely impossible to visualize these permutations and patterns exhaustively. So, if I left out the constraint on exhaustive visualization, the design challenge is to come up with a pattern that plays with any number of partitions of any given number. So, relaxing the requirements on exhaustive visualization where ALL possible k-partitions have to be visualized, could I simply use randomization as a generative idea? I also deliberately wanted to leave k and n as parameters, since that way using a single idea we can produce as many patterns as we would like, but at the same time ensuring that no two patterns are the same!
So, I quickly put together some Matlab code: a function to generate randomized permutations of k-partitions of any given number n. Code is attached at the end of this post, please feel free to use it or modify it in any way, but please acknowledge this original source if you do.
Here are some interesting results:
Say you want to generate randomized partitions of the number 30 into 2 colours. Cast on 30 stitches in colour 1 (blue), use the good old garter stitch, and simply follow the chart here (this came out of the Matlab program by setting n = 30, k = 1). The magic of this type of computation, of course, is that every time you run the program, it will show you a different pattern.
To follow the chart, every row shown needs to be knit twice in garter stitch. So, for example for the square below:
To follow the chart, every row shown needs to be knit twice in garter stitch. So, for example for the square below:
- Row1: Beginning from the bottom right, k1 in colour 1 (blue), change working yarn, and k29 in colour 2 (red).
- Row 2: Turn, k29 in colour 2, k1 in colour 1.
- Row 3: In the next row, there are 18 stitches of colour 1, 12 of colour 2. So, k18 in colour 1, carrying along the colour 2 yarn, then k12 in colour 2.
- Row 4: Turn, k12 with colour2, and k18 with colour 1. Sine in the subsequent row, the pattern is k10 with colour 1, and k20 in colour 2, carry colour 2 along loosely by knitting the first 4 stitches in colour 1, bringing yarn forward, twining colour 2 yarn around working yarn, taking working yarn back again, and continuing to do this, till you reach the colour 2 yarn to the correct stitch.
- Row 5: K10 with colour 1, k20 with colour 2. If you have brought yarn forward from the previous row, colour 2 yarn should be available to knit at the correct stitch.
- Row 6: K20 with colour 2, k10 with colour 1.
- Row 7: K18 with colour 1, when you come to colour 2 after 10 stitches (refer to previous row), carry along colour 2 yarn along back of work in the usual way of twining around the colour 2 yarn around main working yarn for 8 more stitches, then k12 with colour 2.
Continue in this way, bearing in mind to look at the subsequent row and deciding to what stitch number you must carry along the other yarn. I will try and post a photograph of a completed square soon.
Here is a 3 colour pattern of 30 stitches:
Here is a 4-colour pattern of 30 stitches:
And then, the obvious next step is that you can start putting them together to bring out afghan patterns or wall hangings. Here is one in which 9 different squares of 100 stitches on standard 4 mm needles can be put together, with 3 colours (all the 9 squares are unique):
And here is one in which the same square can be knitted 12 times, and you can rotate, invert, or do anything you like to produce interesting variations:
Here is where you can go crazy, set n = 300 (the number of stitches, say for a full afghan on 4 mm needles), set k = 9 (this means you are looking at 9 partitions of the number 300, and using 10 colours to represent them) and follow the number chart to produce this:
At this point you must be thinking, as the numbers and sizes go larger, how do we follow the pattern as we knit? The program below produces a matrix of numbers called R, along with the visual representation. After you choose and fix a colour paletter, R tells you the count of stitches, row by row, that you knit for each successive colour. So, for a 3 colour pattern, if the first row of R = [4, 15], this means knit 4 stitches in colour A, then knit upto the 15th stitch with colour B, and the last remaining stitches in colour C. A bit tedious for some, but not a great deal for those who are used to following charts, or doing any kind of fair-isle, or lace knitting.
What excites me most about this kind of designing, is that, just like many known biological or mathematical generative rule based systems, all the patterns look "similar" or belonging to the same "style" or "typology" of patterns, and yet, no two of them are exactly alike! Instead of the randomization idea, the other extreme would be use a regularization idea, and put together partitions in some deterministic organized and growing way, so that regular visual patterns can emerge.
If anyone decides to knit anything using these ideas, I would love to see links to your work! If you are unable to run programs and would like me to send you some R matrices and charts, set to some number specifications, please do let me know. If someone develops another version of the program, say in something universally available, like Python, that would be most exciting too! I think the code is working fine, but if there are errors, let me know too. Enjoy :)
Ravelry link to pattern.
PS: Special note for those new to garter stitch special properties: Each coloured row in any of the above patterns here to be produced by using two rows of garter knitting, that will produce 1 "ridge". Thus, each coloured row means two rows of knitting. Carry along the yarns as needed for the next row.
PS: Special note for those new to garter stitch special properties: Each coloured row in any of the above patterns here to be produced by using two rows of garter knitting, that will produce 1 "ridge". Thus, each coloured row means two rows of knitting. Carry along the yarns as needed for the next row.
function [A,R] = randomizedPartitionSquare(n,k)
%Function to generate randomized partition squares
% Author: Somwrita Sarkar
% Version: 1
% Date: 6 Jan 2014
% n is the number of stitches, that is the size of your knitted square
% k is the number of partitions. For example, if k = 1, then a number can
% be divided into 2 parts, for example, 5+5 = 10; if k = 2, one possible
% partition is 1 + 1 + 8 = 10; and so on. The number of colors needed to
% knit the square is equal to k+1.
% Run the program as many number of times as the needed numbers of squares.
% Since each square pattern is going to be different, you can think of
% innovative ways to put them together.
% Examples to run code:
%
% Generate initial matrix / square
A = zeros(n,n);
% Now generate the square
for i = 1:n % for each row
for j = 1:k
r(j) = floor(rand*n); % generate partition vector
end
r = sort(r); % sort it in ascending order
R(i,:) = r;
p = 1; % set initial counter for number of columns
c = 1; % set initial color counter, starting color 1
for m = 1:k
A(i,p:r(m)) = c; % first partition set to color 1
p = r(m)+1; % then add number of columns, i.e., for next loop, p goes to (r(1) + 1:r(2));
c = c+1; % for next loop, next color, i.e., color 1 goes to color 2, etc.
end
end
figure
imagesc(A)
% % Initial code for a 3 partition
% for i = 1:n
% r1 = floor(rand*30); % partition 1
% r2 = floor(rand*30); % partition 2
% if r1 < r2
% A(i, 1:r1) = 1;
% A(i,(r1+1):r2) = 2;
% end
% if r1 > r2
% A(i, 1:r2) = 1;
% A(i,(r2+1):r1) = 2;
% end
% end
% figure
% imagesc(A)
end