// title: Knit (javascript with knitout module)
// Knit pulls a loop of yarn back-to-front (or front-to-back, in the case of a back-bed knit) through an existing loop and drops the loop.

// add required [[headers]]:
var knitout = require('./assets/knitout-frontend.js'); // include knitout module 
k = new knitout.Writer({
	carriers: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
});

// determine knitting parameters:
let bed = 'f'; // bed we will knit on
let carriers = ['1', '2', '3', '4']; // list with names of carriers we will use in the piece

// bring in [[carrier]]s:
/*
	* here, we use the knitout extensions [[x-loop-in]] and [[x-yarn-in]] for visualization purposes 
	* note that we would use [[inhook]] instead if we were knitting this on the machine
	* see [[knitting-a-row]] for an example of machine-ready code
*/

// `x-loop-in` for first 2 carriers (get some existing [[loop]]s started so we can visualize a [[stitch]])
k.loopIn('+', bed + '2', carriers[0]);
k.loopIn('+', bed + '6', carriers[1]);

// `x-yarn-in` for last 2 carriers (bring the yarn in so we can use it in operations below)
k.yarnIn('+', bed + '2', carriers[2]);
k.yarnIn('+', bed + '4', carriers[3]);

// knitting pulls a loop of new yarn through the loops on a needle and drops those loops:
/*
parameters:
----------
	* `'+'` (positive direction)
	* `bed + '2'`(knit on pre - defined bed 'f'[front - bed] and on needle number '2')
	* `carrier[2]` (use carrier #3 [recall that the carrier at index 2 is '3'])
*/
k.knit('+', bed + '2', carriers[2]);

// knitting on an empty needle is the same as tucking that needle:
k.knit('+', bed + '4', carriers[3]);

// knitting with no yarns (also called [[drop]]) drops the loops on the needle:
k.knit('+', bed + '6'); // notice that carriers are not passed as a parameter here

// take out [[carrier]]s:
/*
	* here, we use the knitout extensions [[x-yarn-out]] and [[x-loop-in]] for visualization purposes
	* note that we would use [[releasehook]] and [[outhook]] instead if we were knitting this on the machine
*/
k.yarnOut('+', bed + '2', carrier[2]);
k.yarnOut('+', bed + '4', carrier[3]);

k.loopOut(bed + '2'); // notice that direction and carriers are not passed as a parameter here
k.loopOut(bed + '4');

// write the output knitout to a file
k.write('knit.swgn2.k');