//title: Sheet Twisted-Tuck Cast-On (javascript with knitout module)
// Casts on a sheet by knitting twisted tucks on all needles; slow!

//include knitout module:
const knitout = require('knitout'); //include knitout module
const K = new knitout.Writer({ carriers:['1', '2', '3', '4', '5', '6'] });
K.addHeader('Machine', 'Kniterate');

//Parameters:
let min = 1; //needle number of left edge
let max = 20; //needle number of right edge
let carrier = "3"; //carrier name

//Bring in carrier:
K.in(carrier);

//Use a twisted tuck to cast on every stitch.
//Note: this requires a new pass for every stitch, so is pretty slow!
//There are both faster and fancier cast-ons.
//On Kniterate machines, carriers start on the left, so will start with leftmost needle.
for (let n = min; n <= max; n += 1) {
	//tuck alternating needles, making sure to do the left edge:
	K.tuck("-", 'f' + n, carrier);
}

//knit two plain rows to allow cast-on stitches to relax and bring carrier to the right:
for (let n = max; n >= min; n -= 1) {
	K.knit("-", 'f' + n, carrier);
}
for (let n = min; n <= max; n += 1) {
	K.knit("+", 'f' + n, carrier);
}

//...now can knit on [min,max].

K.write('sheet-twisted-tuck-cast-on.kniterate.k');
