\startMPpage



path loopcomponent ;
loopcomponent = ( % we're on a 16 step grid
       (9/16,2+7/16) --
       (1/2,5/2) --
       (1/2,7/2) --
       (3/2,7/2) --
       (2+9/16,2+7/16)
   )
   scaled (1/4) ;

path plaitcomponent ;
plaitcomponent = ( % we're on a 16 step grid
		(7/16,	3+7/16) --
       (1/2,7/2) --
       (3/2,7/2) --
       (2+9/16,2+7/16)
   )
   scaled (1/4) ;


path diagcomponent ;
diagcomponent = ( % we're on a 16 step grid
		(1+7/16,	1+7/16) --
       (2+9/16,2+9/16)
   )
   scaled (1/4) ;


% the two-loop combo at the end of the figure
vardef halfloop (expr loopcomponent) =
   image (
       draw loopcomponent ;
       draw loopcomponent rotated  90 shifted (1,0) ;
   )
enddef ;


% the middle with turning points at edges and straight line inbetween
vardef plait (expr plaitcomponent) =
   image (
      draw plaitcomponent shifted (1/2	,0);
       draw plaitcomponent rotated 180 shifted (1,1) ;
      draw diagcomponent shifted (1/4,0);
   )
enddef ;


% Making line ends straight
linecap := squared ;


% drawing left end
draw halfloop (loopcomponent)
%  withcolor red		%uncomment this line to see what the element is exatly
  withpen pencircle scaled (9/64) ;

% drawing a middle-of-ribbon component
draw plait (plaitcomponent)
%	withcolor blue		%uncomm
	withpen pencircle scaled (9/64);

% repeat the middle
draw plait (plaitcomponent)
	shifted (1/2,0)
	withcolor white
	withpen pencircle scaled (9/64);

% drawing right end
draw halfloop (loopcomponent)
	  rotated 180 shifted (2,1)
	  withcolor white
	  withpen pencircle scaled (9/64) ;



% adding space around the knot-and-plait picture
setbounds currentpicture to boundingbox currentpicture enlarged 1/16 ;

% colouring the background black
addbackground withcolor black ;

% resizing the whole thing to be 5 cm wide (ratio is kept, height is whatever it becomes in scaling)
currentpicture := currentpicture xsized 5cm ;

\stopMPpage
