%% Tabletweaving threading chart for my heart braid


\startMPinclusions

color pink	;
pink:= (255/255,105/255,180/255) ;

patternsize:= 10mm;


% threading direction indicator, tablet in Z position (/)
def dZ (expr sx, sy) =
		picture threadz;
			threadz:= image (
			path d;
			d := (((sx+0.2)*patternsize),((sy+0.2)*patternsize)) -- (((sx+0.8)*patternsize),((sy+0.8)*patternsize));
			draw d withcolor black withpen pencircle scaled 1mm ;
			);
			draw threadz ;
enddef;


% threading direction indicator, tablet in S position (\)
def dS (expr sx, sy) =
		picture threads;
			threads:= image (
			path e;
			e := (((sx+0.2)*patternsize),((sy+0.8)*patternsize)) -- (((sx+0.8)*patternsize),((sy+0.2)*patternsize));
			draw e withcolor black withpen pencircle scaled 1mm ;
			);
			draw threads ;
enddef;



% square indicating thread colour
def thrsq(expr ca, sx, sy) =
	picture threadsq;
		threadsq:= image (
			path s;
			s := unitsquare ;
			linejoin := mitered;
			fill s withcolor ca ;		
			draw s withcolor black withpen pencircle scaled 0.01mm;
		);
		draw threadsq scaled patternsize shifted (sx*patternsize,sy*patternsize);
enddef;


\stopMPinclusions


\startMPpage

nt := 10; % nr of tablets
nh := 4 ; % nr of holes per tablet


% Labels for holes
label ("A", (0,1*patternsize)) ;
label ("B", (0,2*patternsize)) ;
label ("C", (0,3*patternsize)) ;
label ("D", (0,4*patternsize)) ;

% Numbering for tablets
label ("1",(1*patternsize,0)) ;
label ("2",(2*patternsize,0)) ;
label ("3",(3*patternsize,0)) ;
label ("4",(4*patternsize,0)) ;
label ("5",(5*patternsize,0)) ;
label ("6",(6*patternsize,0)) ;
label ("7",(7*patternsize,0)) ;
label ("8",(8*patternsize,0)) ;
label ("9",(9*patternsize,0)) ;
label ("10",(10*patternsize,0)) ;




picture thrpattern ;

thrpattern :=
	image (
		% Threading direction indicators
		dZ (1,5) ;
		dS (2,5) ;
		dZ (3,5) ;
		dS (4,5) ;
		dS (5,5) ;
		dZ (6,5) ;
		dZ (7,5) ;
		dS (8,5) ;
		dZ (9,5) ;
		dS (10,5) ;
		% tablet 1
		thrsq (pink, 1, 1) ;
		thrsq (pink, 1, 2) ;
		thrsq (pink, 1, 3) ;
		thrsq (pink, 1, 4) ;
		% tablet 2
		thrsq (white, 2, 1) ;
		thrsq (white, 2, 2) ;
		thrsq (white, 2, 3) ;
		thrsq (white, 2, 4) ;
		% tablet 3
		thrsq (white, 3, 1) ;
		thrsq (pink, 3, 2) ;
		thrsq (pink, 3, 3) ;
		thrsq (white, 3, 4) ;
		% tablet 4
		thrsq (white, 4, 1) ;
		thrsq (pink, 4, 2) ;
		thrsq (pink, 4, 3) ;
		thrsq (pink, 4, 4) ;
		% tablet 5
		thrsq (pink, 5, 1) ;
		thrsq (pink, 5, 2) ;
		thrsq (pink, 5, 3) ;
		thrsq (pink, 5, 4) ;
		% tablet 6
		thrsq (pink, 6, 1) ;
		thrsq (pink, 6, 2) ;
		thrsq (pink, 6, 3) ;
		thrsq (pink, 6, 4) ;
		% tablet 7
		thrsq (white, 7, 1) ;
		thrsq (pink, 7, 2) ;
		thrsq (pink, 7, 3) ;
		thrsq (pink, 7, 4) ;
		% tablet 8
		thrsq (white, 8, 1) ;
		thrsq (pink, 8, 2) ;
		thrsq (pink, 8, 3) ;
		thrsq (white, 8, 4) ;
		% tablet 9
		thrsq (white, 9, 1) ;
		thrsq (white, 9, 2) ;
		thrsq (white, 9, 3) ;
		thrsq (white, 9, 4) ;
		% tablet 10
		thrsq (pink, 10, 1) ;
		thrsq (pink, 10, 2) ;
		thrsq (pink, 10, 3) ;
		thrsq (pink, 10, 4) ;
		
	) ;
	
	
draw thrpattern shifted ((-0.5*patternsize),(-0.5*patternsize));

\stopMPpage

