-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkp-pattern-test.js
161 lines (121 loc) · 7.84 KB
/
kp-pattern-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
var knitout = require('knitout');
k = new knitout.Writer({carriers:["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]});
k.addHeader('Machine','SWGXYZ');
k.addHeader('Gauge','15');
k.addHeader('Position','Center');
const {testPattern} = require('./pattern');
let startingRow = [0,0,0,0,0,0,0,0,0,0,0,0,0];
let carrier = "6";
let width = 65;
let height = 65;
const front = width%2;
k.inhook(carrier);
// cast on both beds and knit 2 rows
for (let s=width; s>0; s--) {
if (s%2==front) {
k.tuck("-", "f"+(s-1), carrier);
}
else {
k.tuck("-", "b"+(s-1), carrier);
}
}
for (let s=2; s<=width; s++) {
if (s%2==front) {
k.knit("+", "f"+(s-1), carrier);
}
else{
k.knit("+", "b"+(s-1), carrier);
}
}
for (let s=width; s>0; s--) {
if (s%2==front) {
k.knit("-", "f"+(s-1), carrier);
}
else {
k.knit("-", "b"+(s-1), carrier);
}
}
for (let s=2; s<=width; s++) {
if (s%2==front) {
k.knit("+", "f"+(s-1), carrier);
}
else{
k.knit("+", "b"+(s-1), carrier);
}
}
for (let s=width; s>0; s--) {
if (s%2==front) {
k.xfer("f"+(s-1), "b"+(s-1));
}
}
k.releasehook(carrier);
function kp(pattern) {
// Go through each row
// In each row, go through each stitch
let thisRow = pattern[0];
let previousRow = startingRow;
for (let i=0; i<height; i++) {
if (i>0) {
thisRow = pattern[i % pattern.length];
previousRow = pattern[(i + pattern.length - 1) % pattern.length];
}
let output = "";
// In each row, go through each stitch
// "transfer pass" doesn't matter direction
for (let j= width-1; j>=0; j--){
// if the pattern says "1" at this location in the pattern, purl
// otherwise, knit
//DEBUGGG
// console.log(previousRow);
// console.log(i);
if (thisRow[j % thisRow.length] == previousRow[j % thisRow.length]) {
// no transfers needed
}
else if (thisRow[j % thisRow.length] == 1 && previousRow[j % thisRow.length] == 0) {
k.xfer("b"+j, "f"+j);
}
else if (thisRow[j % thisRow.length] == 0 && previousRow[j % thisRow.length] == 1) {
k.xfer("f"+j, "b"+j);
}
else {
console.log("weird number in the pattern?", thisRow[j] );
}
}
// "knitting passes", which have a direction
if (i%2 == 0) { // if this is an even row, go leftwards
for (let j= width-1; j>=0; j--){
// if the pattern says "1" at this location in the pattern, purl
// otherwise, knit
if (thisRow[j % thisRow.length] == 1) {
// xfer("b"+j, "f"+j);
k.knit("-", "f"+j, carrier);
}
else {
// xfer("f"+j, "b"+j);
k.knit("-", "b"+j, carrier);
}
}
}
else { // if this is an odd row, go rightwards
for (let j=0; j< width; j++){
if (thisRow[j % thisRow.length] == 1) {
// xfer("b"+j, "f"+j);
k.knit("+", "f"+j, carrier);
}
else {
// xfer("f"+j, "b"+j);
k.knit("+", "b"+j, carrier);
}
}
}
}
for (let j=width-1; j>=0; j--){
// reset back bed knits to front
if (thisRow[j % thisRow.length] == 0) {
k.xfer("b"+j, "f"+j);
}
}
}
kp(testPattern);
k.outhook(carrier);
k.write('kp-pattern-test.k');