-
Notifications
You must be signed in to change notification settings - Fork 5
/
lace.js
executable file
·114 lines (99 loc) · 2.38 KB
/
lace.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
#!/usr/bin/env node
//basic left/right transfer-based lace:
const Carrier = "7";
//'-' is move stitches left, '+' is move stitches right
const Pattern = [
"..--.....+..",
"...-....--..",
"...++....-..",
"...+.....++.",
];
const Margin = 6;
const Width = Pattern[0].length * 4 + 2 * Margin;
const Height = Pattern.length * 6;
console.log(";!knitout-2");
console.log(";;Carriers: 1 2 3 4 5 6 7 8 9 10");
console.log('x-stitch-number 70');
//Basic alternating tucks cast-on:
console.log('inhook ' + Carrier);
for (let n = Width-1; n >= 0; --n) {
if ((Width-1 - n) % 2 === 0) {
console.log('knit - f' + n + ' ' + Carrier);
}
}
for (let n = 0; n <= Width-1; ++n) {
if ((Width-1 - n) % 2 !== 0) {
console.log('knit + f' + n + ' ' + Carrier);
}
}
//'dir' will track the direction of the next pass:
let dir = '-';
function knitRow() {
if (dir === '+') {
for (let n = 0; n < Width; ++n) {
console.log('knit + ' + 'f' + n + ' ' + Carrier);
}
dir = '-';
} else { //dir === '-'
for (let n = Width-1; n >= 0; --n) {
console.log('knit - ' + 'f' + n + ' ' + Carrier);
}
dir = '+';
}
}
//a few starting rows:
for (let r = 0; r < 8; ++r) {
knitRow();
}
console.log('releasehook ' + Carrier);
//run the pattern:
for (let rowIndex = 0; rowIndex < Height; ++rowIndex) {
//duplicate pattern row to get full-width row:
const patternRow = Pattern[(Height - 1 - rowIndex) % Pattern.length];
let row = "";
for (let i = 0; i < Margin; ++i) {
row += '.';
}
for (let col = 0; col < Width - 2 * Margin; ++col) {
row += patternRow[col % patternRow.length];
}
for (let i = 0; i < Margin; ++i) {
row += '.';
}
console.warn(row); //DEBUG
//handle transfers indicated in the pattern:
for (let n = 0; n < Width; ++n) {
console.log('xfer f' + n + ' b' + n);
}
console.log('rack +1');
for (let n = 0; n < Width; ++n) {
if (row[n] === '+') {
console.log('xfer b' + n + ' f' + (n+1));
}
}
console.log('rack -1');
for (let n = 0; n < Width; ++n) {
if (row[n] === '-') {
console.log('xfer b' + n + ' f' + (n-1));
}
}
console.log('rack 0');
for (let n = 0; n < Width; ++n) {
if (row[n] === '.') {
console.log('xfer b' + n + ' f' + n);
}
}
//knit two rows:
knitRow();
knitRow();
}
//a few ending rows:
for (let r = 0; r < 8; ++r) {
knitRow();
}
//finish up with yarn:
console.log('outhook ' + Carrier);
//drop:
for (let n = 0; n < Width; ++n) {
console.log('drop ' + 'f' + n);
}