\startMPinclusions

patternsize:= 20mm;

def lhl(expr ca,cb,sx,sy) =
    picture lefthandloop;
    lefthandloop := image (
        path p, q, r ;
        p := fullcircle scaled 4mm ;
        q := p shifted (0mm,10mm) ;
        r := center p .. (5mm,5mm) .. center q ;
        r := r cutbefore (p intersectionpoint r) cutafter (q
intersectionpoint r) ;

        draw r withpen pencircle scaled 0.2mm withcolor black ; % the connecting curve
        fill p withcolor ca;
        draw p withpen pencircle scaled 0.2mm withcolor black ; % upper shank
        fill q withcolor cb;
        draw q withpen pencircle scaled 0.2mm withcolor black ; % lower shank
        );
    draw lefthandloop shifted (sx*patternsize,sy*patternsize);
enddef;

path s, t, u ;

s := fullcircle scaled 4mm shifted (4mm,0mm);
t := s shifted (0mm,10mm) ;
u := center s .. (0mm,8mm) .. center t ;

u := u cutbefore (s intersectionpoint u) cutafter (t intersectionpoint u) ;



def lbl(expr sx,sy) =
    picture leftblank;
    leftblank := image (
        draw r withpen pencircle scaled 0.2mm withcolor .6white ; % the connecting curve
        fill p withcolor .8white;
        draw p withpen pencircle scaled 0.2mm withcolor .6white ; % upper shank
        fill q withcolor .8white;
        draw q withpen pencircle scaled 0.2mm withcolor .6white ; % lower shank
        );
    draw leftblank shifted (sx*patternsize,sy*patternsize);
enddef;

def rhl(expr ca,cb,sx,sy) =
    picture righthandloop;
    	righthandloop := image (
		draw u withpen pencircle scaled 0.2mm withcolor black ;
		fill s withcolor ca ;
		draw s withpen pencircle scaled 0.2mm withcolor black ;
		fill t withcolor cb ;
		draw t withpen pencircle scaled 0.2mm withcolor black ;
		);
    draw righthandloop shifted (sx*patternsize,sy*patternsize);
enddef;


def rbl(expr sx,sy) =
    picture rightblank;
    rightblank := image (

	path s, t, u ;

	s := fullcircle scaled 4mm shifted (4mm,0mm);
	t := s shifted (0mm,10mm) ;
	u := center s .. (0mm,8mm) .. center t ;

   	u := u cutbefore (s intersectionpoint u) cutafter (t intersectionpoint u) ;


    	draw u withpen pencircle scaled 0.2mm withcolor .6white ; % the connecting curve
    	fill s withcolor .8white;
    	draw s withpen pencircle scaled 0.2mm withcolor .6white ; % upper shank
    	fill t withcolor .8white;
    	draw t withpen pencircle scaled 0.2mm withcolor .6white ; % lower shank
        );
    draw rightblank shifted (sx*patternsize,sy*patternsize);
enddef;


picture grid ;
grid :=
	image (
		width := 3cm ;
		height := 7cm ;
		unit := cm ;
		draw vlingrid (0, width/unit, 1/10, width, height) withcolor .6white ; 
		draw hlingrid (0, height/unit, 1/10, height, width) withcolor .6white ;
		draw vlingrid (0, width/unit, 1/2, width, height) withcolor .4blue ; 
		draw hlingrid (0, height/unit, 1/2, height, width) withcolor .4blue ;
		draw vlingrid (0, width/unit, 1, width, height) withcolor .6red ;
		draw hlingrid (0, height/unit, 1, height, width ) withcolor .6red ;
	) ;


\stopMPinclusions


\startMPpage

%draw grid ;

% Loops: syntax for coloured 'color top, color bottom, loc x, loc y'; for blank only 'loc x, loc y'

%% LEFT
% -- La --
lhl	(yellow,red,0,3);
% lbl(0,3);

% -- Lb --
lhl	(yellow,red,0,2);
% lbl(0,2);

% -- Lc --
lhl	(yellow,red,0,1);
% lbl(0,1);

% -- Ld --
% lhl	(color, color, 0,0);
lbl	(0,0);



%% RIGHT

% -- Ra --
% rhl	(red,yellow,1,3);
rbl	(1,3);

% -- Rb --
rhl	(red,yellow,1,2);
% rbl(1,2);

%  -- Rc --
rhl	(red,yellow,1,1);
% rbl(1,1);

% -- Rd --
% rhl(blue,blue,1,0);
rbl(1,0);


% Paths

% step 1
drawarrow (2.4cm,6.5cm) .. (1.8cm,6.0cm) .. (2.4cm,5.5cm) .. (2.8cm,5cm) .. (1.8cm,4.2cm) .. (0.8cm,2.0cm) .. (0.3cm,2.0cm) withcolor blue withpen pencircle scaled .2mm ;
		


\stopMPpage
