//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', '7', '8', '9', '10'] });
K.addHeader('Machine', 'SWGN2');

//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.inhook(carrier);
//Set stitch table entry for cast-on:
K.stitchNumber(101);

//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 SWGN2 machines, carriers start on the right, so will start with rightmost needle.
//Miss the rightmost needle to ensure yarn inserting hook is parked to its right instead of left:
K.miss("-", 'f' + max, carrier);
for (let n = max; n >= min; n -= 1) {
	K.tuck("+", 'f' + n, carrier);
}
//Set stitch table entry for knitting:
K.stitchNumber(105);
//knit a plain row to bring the carrier back to the right:
for (let n = min; n <= max; n += 1) {
	K.knit("+", 'f' + n, carrier);
}
//send out yarn inserting hook; it is no longer needed to hold the yarn in place:
K.releasehook(carrier);

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

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