-
Notifications
You must be signed in to change notification settings - Fork 0
/
filled_diamonds.js
120 lines (99 loc) · 3.27 KB
/
filled_diamonds.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
#!/bin/sh
':' //; exec "$(command -v nodejs || command -v node)" "$0" "$@"
// Parameters
const Width = 30; // Width of the rectangle
const Height = 40; // Height of the rectangle
const Carrier = "3"; // Carrier for knitting
const LatticeWidth = 6; // Width of each diamond lattice
const LatticeHeight = 6; // Height of each diamond lattice
const CastOnStitch = 61; // Cast-on stitch type
const KnittingStitch = 63; // Knitting stitch type
const DoBindOff = true;
console.log(";!knitout-2");
console.log(";;Carriers: 1 2 3 4 5 6 7 8 9 10");
console.log("x-presser-mode auto");
// Functions
function castOn(carrier) {
console.log("inhook " + carrier);
console.log("x-stitch-number " + CastOnStitch);
let min = 1;
let max = min + Width - 1;
for (let n = max; n >= min; --n) {
if ((max - n) % 2 === 0) {
console.log("tuck - f" + n + " " + carrier);
}
}
for (let n = min; n <= max; ++n) {
if ((max - n) % 2 === 1) {
console.log("tuck + f" + n + " " + carrier);
}
}
}
function knitFrontRow(min, max, carrier) {
for (let n = min; n <= max; ++n) {
console.log(`knit + f${n} ${carrier}`);
}
for (let n = max; n >= min; --n) {
console.log(`knit - f${n} ${carrier}`);
}
}
// Diamond lattice formation
function transferDiamond(min, max, carrier) {
let center = Math.floor((min + max) / 2);
for (let row = 0; row < LatticeHeight; ++row) {
let left = center - row;
let right = center + row;
if (left >= min && right <= max) {
console.log(`xfer f${left} b${left}`);
console.log(`xfer f${right} b${right}`);
}
knitFrontRow(min, max, carrier);
}
for (let row = LatticeHeight - 1; row >= 0; --row) {
let left = center - row;
let right = center + row;
if (left >= min && right <= max) {
console.log(`xfer b${left} f${left}`);
console.log(`xfer b${right} f${right}`);
}
knitFrontRow(min, max, carrier);
}
}
function bindOff(shouldBindOff, carrier) {
if (shouldBindOff) {
let min = 1;
let max = min + Width - 1;
console.log("inhook " + carrier);
console.log("x-stitch-number " + KnittingStitch);
for (let n = min; n < max; ++n) {
console.log("xfer f" + n + " b" + n);
console.log("rack 1.0");
console.log("xfer b" + n + " f" + (n + 1));
console.log("rack 0.0");
console.log("knit + f" + (n + 1) + " " + carrier);
}
console.log("knit - f" + max + " " + carrier);
console.log("knit + f" + max + " " + carrier);
// Drop stitches after bind-off
dropStitches(max, carrier);
}
}
function dropStitches(max, carrier) {
console.log("rack 0.25");
for (let n = 1; n <= max; ++n) {
console.log("drop b" + n + " " + carrier);
console.log("drop f" + n + " " + carrier);
}
}
// Main operation
let min = 1;
let max = min + Width - 1;
// Cast on
castOn(Carrier);
// Create diamond lattice pattern over the height of the rectangle
for (let i = 0; i < Height; i += LatticeHeight) {
transferDiamond(min, max, Carrier);
}
// Bind off at the end
bindOff(DoBindOff, Carrier);
console.log("outhook " + Carrier);