applications.collages.collageAlgebra:
{
  legwidth = const(.03),
  ntColour = const(.8),
  arrow-length = const(1.5),
  direction = const(20),
  direction = rotate(#direction),
  
  sample-outline = { polygon((0,-2),(6,-2),(6,2),(0,2))},
  sample-filled = { filledPolygon((0,-2),(6,-2),(6,2),(0,2))[#ntColour,#ntColour,#ntColour] }
                  + #sample-outline,
  sample-arrow = { filledPolygon((0,0),(#arrow-length / 4,#arrow-length),
      (-#arrow-length / 4,#arrow-length))},
  sample = #sample-filled + #sample-outline + #sample-arrow,
  rightarrow = { filledPolygon((2,-.3),(3.3,-.3),(3.3,-.75),(4,0),(3.3,.75),(3.3,.3),(2,.3)) },
  updownarrow = { filledPolygon((2.7,-.3),(2.25,-.3),(3,-1),(3.75,-.3),(3.3,-.3),(3.3,.3),(3.75,.3),(3,1),(2.25,.3),(2.7,.3)) },
  uparrow = { filledPolygon((2.7,-1),(3.3,-1),(3.3,.3),(3.75,.3),(3,1),(2.25,.3),(2.7,.3)) },
  +-arrow = { curve((3,-1) right (.55,0),
                    (4,0) right (0,.55),
                    (3,1) right (-.55,0)) width(.02) },
  +arrowdirection = translate(0,-#arrow-length) . rotate(-90) . translate(3,1) . use(direction),
  -arrowdirection = translate(0,-#arrow-length) . rotate(-90) . translate(3,-1) . use(direction),
  S = #sample transformed by direction + #rightarrow transformed by direction,
  S0 = #S,
  P = #sample transformed by direction,
  UD = #sample transformed by direction + #updownarrow transformed by direction,
  U = #sample transformed by direction + #uparrow transformed by direction,
  +- = #sample transformed by direction + #+-arrow transformed by direction
       + #sample-arrow transformed by +arrowdirection
       + #sample-arrow transformed by -arrowdirection,
  -  = #sample transformed by direction + #+-arrow transformed by direction
       + #sample-arrow transformed by -arrowdirection,
  +  = #sample transformed by direction + #+-arrow transformed by direction
       + #sample-arrow transformed by +arrowdirection,
  
  body = {
    filledcurve((.3,0) left (0,0) right (.1,.6),
                (1.6,.9) right (.6,0),
                (2.5,0) right (0,-.5),
                (1.6,-.9) right (-.6,0),
                (.3,0) left (.1,-.6) right (0,0)
               ),
    filledcurve((2.47,0) left (0,0) right (.2,.4),
                (3,0) right (0,-.4),
                (2.47,0) left (.2,-.4) right (0,0)
               ),
    filledcurve((3,0) left (0,0) right (0,.2),
                (3.5,.35) right (.15,.15),
                (4,.35) right (.15,.15),
                (4.5,0) right (0,-.15),
                (4,-.35) right (-.15,.15),
                (3.5,-.35) right (-.15,.15),
                (3,0) left (0,-.2) right (0,0)
               ),
    filledcurve((4.46,0) left (0,0) right (0,.9),
                (5,.65) right (.07,-.03),
                (5.5,.35) left (-.05,.15) right (.2,0),
                (5.7,.05) left (.05,.25) right (-.1,0),
                (5.52,.22) left (.18,0) right (.0,-.1),
                (5.57,0) left (.02,.12) right (.02,-.12),
                (5.52,-.22) left (.0,.1) right (.18,0),
                (5.7,-.05) left (-.1,0) right (.05,-.25),
                (5.5,-.35) left (.2,0) right (-.05,-.15),
                (5,-.65) left (.07,.03),
                (4.46,0) left (0,-.9) right (0,0)
               )
        },
  leg1 = { polyline((0,0), (-.2,1), (-1.9,1.1), (-2.5,1.2), (-3.2,1.7)) width #legwidth },
  leg2 = { polyline((0,0), (.3,1), (-.3,1.8), (-.4,2.1), (-.4,2.4)) width #legwidth },
  leg3 = { polyline((0,0),(.2,.6),(.9,1.2),(1,1.5),(1,1.6)) width #legwidth },
  
  L1 = { polyline((0,0), (-.2,1), (-1.9,1.1), (-2.5,1.2), (-3.2,1.7))[#ntColour,#ntColour,#ntColour] width #legwidth },
  L2 = { polyline((0,0), (.3,1), (-.3,1.8), (-.4,2.1), (-.4,2.4))[#ntColour,#ntColour,#ntColour] width #legwidth },
  L3 = { polyline((0,0),(.2,.6),(.9,1.2),(1,1.5),(1,1.6))[#ntColour,#ntColour,#ntColour] width #legwidth },
  
  flipV = scale(1,-1),
  legTrans1 = translate(2.8,.2),
  legTrans2 = translate(3.4,.2),
  legTrans3 = translate(4,.2),
  legPos1 = use(legTrans1) . use(direction),
  legPos2 = use(legTrans2) . use(direction),
  legPos3 = use(legTrans3) . use(direction),
  legPos4 = use(legTrans1) . use(flipV) . use(direction),
  legPos5 = use(legTrans2) . use(flipV) . use(direction),
  legPos6 = use(legTrans3) . use(flipV) . use(direction),
  ant = <legPos1,legPos2,legPos3,legPos4,legPos5,legPos6, #body transformed by direction>,
  
  legMove1 = rotate(20),
  legMove1 = <legMove1>,
  
  legMove2 = rotate(-10),
  legMove2 = <legMove2>,
  
  id = scale(1),
  smallStep = translate(20,7.28),
  smallStep = <id, smallStep>,
  medStep = translate(23,8.37),
  medStep = <id, medStep>,
  bigStep = translate(26,9.46),
  bigStep = <id, bigStep>,
  
  one = <id>,
  
  twoA = translate(-4,-1.45),
  twoB = translate(4.5,1.64),
  two = <twoA, twoB>,
  
  threeA = translate(-8,-2.91),
  threeB = use(id),
  threeC = translate(6.5, 2.37),
  three = <threeA,threeB,threeC> ,
  
%  up1 = translate(-.36, 1),
%  up1 = <up1>,
  
%  up2 = translate(-.91, 2.5),
%  up2 = <up2>,
  
  up1 = translate(-.55, 1.5),
  up1 = <up1>,
  
  up2 = translate(-.73, 2),
  up2 = <up2>,
  
  plus = rotate(10),
  plus = <plus>,
  
%  minus = rotate(-10),
%  minus = <minus>,

  flip = rotate(-#direction) . scale(1,-1) . rotate(#direction),
  flip = <flip>,
  
  scaleDown = scale(.2),
  scaleDown = <scaleDown>
  
}
