#title: Sheet All-Needle Cast-On (plain python)
# Casts on a sheet by knitting all needles and then stacking front and back stitches to produce a decorative welt.

#Write header:
print(';!knitout-2')
print(';;Machine: SWGN2')
print(';;Carriers: 1 2 3 4 5 6 7 8 9 10')

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

#Bring in carrier:
print(f"inhook {carrier}")
#Set stitch table entry for cast-on:
print(f"x-stitch-number 101")

#On SWGN2 machines, carriers start on the right,
#so will start by tucking all needles right-to-left,
#and will be sure to tuck the leftmost back-bed needle last.

#Need to use quarter-pitch racking to tuck all needles in one pass:
print(f"rack -0.75")

for n in range(max, min-1, -1):
	print(f"tuck - f{n} {carrier}")
	print(f"tuck - b{n} {carrier}")

#Return to aligned racking:
print(f"rack 0")

#Set stitch table entry for knitting:
print(f"x-stitch-number 105")

#Do a rows of plain knitting on the front and back:
for n in range(min, max+1, 1):
	print(f"knit + f{n} {carrier}")
for n in range(max, min-1, -1):
	print(f"knit - b{n} {carrier}")
#One can knit more on the front or back beds here to make a larger "welt" at the edge.

#Stack back-bed stitches with front-bed stitches:
for n in range(max, min-1, -1):
	print(f"xfer b{n} f{n}")

#knit a plain row through the stacked stitches and return carrier to the right edge:
for n in range(min, max+1, 1):
	print(f"knit + f{n} {carrier}")

#send out yarn inserting hook; it is no longer needed to hold the yarn in place:
print(f"releasehook {carrier}")

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