applications.collages.collageAlgebra:
  attributes r,g,b,rc,gc,bc,f;
{
  ntColour = const(.8),
  ntColour2 = const(.6),
  
  d = const(12.5),
  angle = const(5),
  rot = const(15),
  x1 = const(#d * sin(#angle / 2)),
  y1 = const(#d * cos(#angle / 2)),
  x2 = const(-#x1),
  y2 = const(#y1),
  x30 = const((#d - 1) * -sin(#angle / 2)),
  y30 = const((#d - 1) * cos(#angle / 2)),
  x40 = const(-#x30),
  y40 = const(#y30),
  x3 = const(#x30 * cos(#rot) - #y30 * sin(#rot)),
  y3 = const(#x30 * sin(#rot) + #y30 * cos(#rot)),
  x4 = const(#x40 * cos(#rot) - #y40 * sin(#rot)),
  y4 = const(#x40 * sin(#rot) + #y40 * cos(#rot)),

  part0 = { filledPolygon((#x1, #y1), (#x2, #y2), (#x3, #y3), (#x4, #y4))<r,g,b;rc=.5,gc=.5,bc=.5>
              },
  part = { filledPolygon((#x1, #y1), (#x2, #y2), (0,0))<r,g,b;rc=.5,gc=.5,bc=.5>
              },
  S+ = { filledPolygon((#x1, #y1), (#x2, #y2), (#x3, #y3), (#x4, #y4))
               [#ntColour2,#ntColour2,#ntColour2],
             polygon((#x1, #y1), (#x2, #y2), (#x3, #y3), (#x4, #y4))
                        },
  S = { filledPolygon((#x1, #y1), (#x2, #y2), (#x3, #y3), (#x4, #y4))
               [#ntColour,#ntColour,#ntColour],
             polygon((#x1, #y1), (#x2, #y2), (#x3, #y3), (#x4, #y4))
                        },
                                                
  shrink = scale((#d - 1) / #d) . rotate(#rot),
  shrink = < #part0, shrink >,
  
  s0 = rotate(0 * #angle),
  s1 = rotate(1 * #angle),
  s2 = rotate(2 * #angle),
  s3 = rotate(3 * #angle),
  s4 = rotate(4 * #angle),
  s5 = rotate(5 * #angle),
  s6 = rotate(6 * #angle),
  s7 = rotate(7 * #angle),
  s8 = rotate(8 * #angle),
  45-deg = <s0, s1, s2, s3, s4, s5, s6, s7, s8 >,
  
  t0 = rotate(0),
  t1 = rotate(45),
  t2 = rotate(90),
  t3 = rotate(135),
  t4 = rotate(180),
  t5 = rotate(225),
  t6 = rotate(270),
  t7 = rotate(315),
  full = < t0, t1, t2, t3, t4, t5, t6, t7 >,
  
  c = colourOperation(f|1/10:1),
  chooser = colourOperation(rc|.5:1,gc||1/3:.5,bc||1/3:.5),
  chooseg = colourOperation(rc||1/3:.5,gc|.5:1,bc||1/3:.5),
  chooseb = colourOperation(rc||1/3:.5,gc||1/3:.5,bc|.5:1),
  chooserg = colourOperation(rc|.5:1,gc|.5:1,bc||1/3:.5),
  chooserb = colourOperation(rc|.5:1,gc||1/3:.5,bc|.5:1),
  choosegb = colourOperation(rc||1/3:.5,gc|.5:1,bc|.5:1),
  choosergb = colourOperation(rc|.5:1,gc|.5:1,bc|.5:1),
  set = colourOperation(r|val(f):val(rc),g|val(f):val(gc),b|val(f):val(bc))
    
}
