Celtic MetaPost

I love the knots and plaits used as border patterns and fills in the Celtic manuscripts of the the 8th and 9th century, like Book of Kells and Lindisfarne Gospels. The patterns are very geometric and there are good books on this, so drawing the patterns isn’t really difficult – but require a lot of attention to detail and time.

I’ve tried drawing some of the easier plaits with paper and pencil, and wasn’t that successful – I managed to draw the basic pattern, but I always messed up the intersections when inking the outlines or, at latest, when painting the background or plait. Drawing by hand on grid in a vector graphics program wasn’t that easy, either, and my mouse arm hated me after that. So when I learned what MetaPost is, I thought that it might be a solution. Looks like this wasn’t a bad idea at all…

A simple celtic knot

Here’s my first Celtic MP knot. My solution is different from drawing on paper, instead I coded my drawing like scrapbooking, i.e. layering cut pieces of paper on top of and next to each other: first I put down a black background, then add for identical pieces of paper on top of it to create the knot.

 

My first MetaPost knot

 

Here’s the full code for the above, including the ConTeXt code that allows me to compile the pic; if you use LaTeX or some other system, change the MPinclusion ja MPpage codes to the ones appropriate to your system.

\startMPinclusions

ps:= 8mm;

def bg(expr bw,bh,bc) =
	path b ; b := (0,0) -- (bw*ps,0) -- (bw*ps,bh*ps) -- (0,bh*ps) -- (0,0) -- cycle;
	fill b withcolor bc;
enddef;

\stopMPinclusions

\startMPpage

bg (4,4,black) ;

picture loopcomp ;
  loopcomp :=
	image (
	interim linecap := squared;
	draw ((9/16*ps),(2+7/16)*ps) -- (0.5*ps,2.5*ps) -- (0.5*ps,3.5*ps) --
              (1.5*ps,3.5*ps) -- ((2+9/16)*ps, (2+7/16)*ps)
              withcolor white withpen pencircle scaled (9/16*ps) ;
	) ;

draw loopcomp ;
draw loopcomp rotated 90 shifted (4*ps,0);
draw loopcomp rotated 180 shifted (4*ps,4*ps);
draw loopcomp rotated 270 shifted (0,4*ps);

\stopMPpage

 

A simple Celtic plait

The knot above can fairly easily be expanded into a plait:

A simple Celtic plait

 

And here’s the code; probably not even close to optimized, but it works. Some of it is code that I got from Hans Hagen who sent me a cleaner solution to the above knot.

\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) ;

vardef halfloop (expr loopcomponent) =
   image (
       draw loopcomponent ;
       draw loopcomponent rotated  90 shifted (1,0) ;
   )
enddef ;

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 ;

interim linecap := squared ;

draw halfloop (loopcomponent)
  withcolor white
  withpen pencircle scaled (9/64) ;

draw plait (plaitcomponent)
	withcolor white
	withpen pencircle scaled (9/64);

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

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

setbounds currentpicture to boundingbox currentpicture enlarged 1/16 ;

addbackground withcolor black ;

currentpicture := currentpicture xsized 2cm ;

\stopMPpage

 

Josephine Knot

I learn more about MetaPost every time I use it to code something new. The Josephine knot is from the same book as the above, “The Celtic Design Book” by Aidan Meehan (p. 199).

Josephine Knot Motif

I’ve been told that a programmer looks at these graphics, he sees a loop(s) with cuts at intersections. My approach is different, closer to what is described in the book. Thus this knot follows the previous ones in that it consists of pieces of thick line. However, this time I had the brain to code each element (end, longer curve, shorter curve, line) as starting from origin on the coordinates, which meant less math to deal with. Then I shift and rotate the pieces as needed; if you look closely, there’re two of each sort in this graphic.


%%% Design source: Aidan Meehan, The Celtic Design Book. Thames & Hudson. Page 199.

\startMPpage

% square linecaps ensure crisp crossings
linecap:= squared ;

% end piece/loop
picture ending ;
		ending :=
			image (
				draw (65/64,1/64) -- (1,0) -- (0,0) -- (0,3) -- (1,3) -- (2,2) ;
			);

% the longer curve piece
picture lcurve ;
	lcurve :=
		image (
			draw (1/64,2+1/64) -- (0,2) -- (0,1) -- (1,0) -- (2,0) -- (2+1/64,1/64) ;
		) ;
% the shorter curve piece
picture scurve ;
	scurve :=
		image (
			draw (0,1) -- (1,0) -- (2,0) -- (2+1/64,1/64) ;
		) ;

% the straight line in the middle
picture dline ;
	dline :=
		image (
			draw (1/2,1/2) -- (3/2,3/2) ;
			) ;

% don't touch, only this pen width works

drawoptions(withpen pencircle scaled 5/8 withcolor white);

draw ending shifted (1/2,1/2) ;
draw lcurve shifted (3/2,1/2) ;
draw scurve shifted (7/2,1/2) ;
draw dline shifted (2,1);

draw ending rotated 180 shifted (15/2,7/2) ;
draw scurve rotated 180 shifted (9/2,7/2) ;
draw dline shifted (4,1) ;
draw lcurve rotated 180 shifted (13/2,7/2);

setbounds currentpicture to boundingbox currentpicture enlarged 1/8 ;

addbackground withcolor black ;

currentpicture := currentpicture xsized 4cm ;

\stopMPpage