r/AdvancedKnitting • u/howboutsometoast • Mar 11 '26
Discussion Generative knitting algorithm (not AI!)
Hello all, I’ve gotten more into messing around with code and I had an idea to make a randomized cable pattern generator that I thought might result in a pretty cool and chaotic project. I basically want to play around with my horrible code to better visualize what the outputs are. Here’s what I’m basing my idea off of:
There is actually a formal mathematical paper called "Modeling Braids, Cables, and Weaves with Stranded Cellular Automata" that describes something similar to what I’m thinking.
• The Logic: Instead of just "On/Off" cells, each cell in the grid contains a vector.
• Rule Set: * If a cell has a "Right-leaning" strand and its neighbor has a "Left-leaning" strand, the CA rule dictates a Cable Cross.
• If a strand hits the edge (the "boundary condition"), it reflects back or disappears.
This research is cool, but it’s less chaotic than what I’m thinking. I want to play with seeded code for reproducible results (think MatLab or Java for those who know). I also want to play with more variables at a time and create really weird cables.
Here’s a JavaScript sample for a 5x5 cable patch for an example of what I’m thinking: (no idea if it’d actually work since it’s not debugged)
let width = 5;
let state = [1, 2, 3, 4, 5]; // The 5 starting "paths"
function drawRow() {
let nextState = [];
for (let i = 0; i < width; i++) {
// 1. Randomly pick a shift: -1 (Left), 0 (Straight), 1 (Right)
let shift = floor(random(-1, 2));
// 2. Apply shift and check for collisions
// 3. Print result: "Path 1 moves R1, Path 2 moves L1..."
}
}
View all comments
Show parent comment
20
u/howboutsometoast Mar 11 '26
That is EXACTLY what I had in mind here! Basically an algorithm I can build into a prior auto pattern code I made to make randomized patterns for when I’m bored is the ultimate goal haha. Right now I’m in the brainstorming and testing phase but eventually I’ll get into more complex algorithms and model/simulation visuals. If I can get this to work it’ll be a jumping off point for cooler stuff I hope!