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

import knitout
K = knitout.Writer('1 2 3 4 5 6 7 8 9 10');
K.addHeader('Machine', 'SWGN2');

#Parameters:
min = 1 #needle number of left edge
max = 20 #needle number of right edge
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' + str(max), carrier)
for n in range(max, min-1, -1):
	K.tuck("+", 'f' + str(n), carrier)
#Set stitch table entry for knitting:
K.stitchNumber(105)
#knit a plain row to bring the carrier back to the right:
for n in range(min, max+1, 1):
	K.knit("+", 'f' + str(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')
