applications.collages.collageAlgebra:
{  
  angle = const(15),
  l = const(2 * sin(#angle / 2)),
  v1x = const(#l * sin(2 * #angle)),
  v1y = const(#l * cos(2 * #angle)),
  v2x = const(#v1x + #l * sin(#angle)),
  v2y = const(#v1y + #l * cos(#angle)),
  v3x = const(#v2x),
  v3y = const(#v2y + #l),
  v4x = const(sin(#angle / 2)),
  v4y = const(cos(#angle / 2)),
  v5x = const(-sin(#angle / 2)),
  v5y = const(cos(#angle / 2)),
  v6x = const(#v5x + #l * sin(2 * #angle)),
  v6y = const(#v5y - #l * cos(2 * #angle)),
  v7x = const(#v6x + #l * sin(#angle)),
  v7y = const(#v6y - #l * cos(#angle)),
  v8x = const(#v7x),
  v8y = const(#v7y - #l),
  
  triangle
    = { polygon( (0,0), (#v4x, #v4y), (-#v4x, #v4y) )},
  
  darkTriangle
    = { filledPolygon( (0,0), (#v4x, #v4y), (-#v4x, #v4y) )[.15,.5,.9]}
      + #triangle,
  
  lightTriangle
    = { filledPolygon( (0,0), (#v4x, #v4y), (-#v4x, #v4y) )[.45,.7,.9]}
      + #triangle,
   
  A = #darkTriangle,
  B = #lightTriangle,
  
  versatile
    = {
        polygon(
          (0,0),
          (#v1x,#v1y),
          (#v2x,#v2y),
          (#v3x,#v3y),
          (#v4x,#v4y),
          (#v5x,#v5y),
          (#v6x,#v6y),
          (#v7x,#v7y),
          (#v8x,#v8y) )
        },
        
  darkVersatile
    = {
        filledPolygon(
          (0,0),
          (#v1x,#v1y),
          (#v2x,#v2y),
          (#v3x,#v3y),
          (#v4x,#v4y),
          (#v5x,#v5y),
          (#v6x,#v6y),
          (#v7x,#v7y),
          (#v8x,#v8y) )[.15,.5,.9]
        } + #versatile,
  
  lightVersatile
    = {
        filledPolygon(
          (0,0),
          (#v1x,#v1y),
          (#v2x,#v2y),
          (#v3x,#v3y),
          (#v4x,#v4y),
          (#v5x,#v5y),
          (#v6x,#v6y),
          (#v7x,#v7y),
          (#v8x,#v8y) )[.45,.7,.9]
        } + #versatile,
  
  versatileA
    = {
        filledPolygon(
          (0,0),
          (#v1x,#v1y),
          (#v8x,#v8y) )[0,.4,.9],
        filledPolygon(
          (#v1x,#v1y),
          (#v2x,#v2y),
          (#v7x,#v7y),
          (#v8x,#v8y) )[.15,.5,.9],
        filledPolygon(
          (#v2x,#v2y),
          (#v3x,#v3y),
          (#v6x,#v6y),
          (#v7x,#v7y) )[.3,.6,.9],
        filledPolygon(
          (#v3x,#v3y),
          (#v4x,#v4y),
          (#v5x,#v5y),
          (#v6x,#v6y) )[.45,.7,.9]
        } + #versatile,
  
  versatileB
    = {
        filledPolygon(
          (0,0),
          (#v1x,#v1y),
          (#v8x,#v8y) )[.45,.7,.9],
        filledPolygon(
          (#v1x,#v1y),
          (#v2x,#v2y),
          (#v7x,#v7y),
          (#v8x,#v8y) )[.3,.6,.9],
        filledPolygon(
          (#v2x,#v2y),
          (#v3x,#v3y),
          (#v6x,#v6y),
          (#v7x,#v7y) )[.15,.5,.9],
        filledPolygon(
          (#v3x,#v3y),
          (#v4x,#v4y),
          (#v5x,#v5y),
          (#v6x,#v6y) )[0,.4,.9]
        } + #versatile,
  
  S1x = const(3/2 * #l * sin(2 * #angle)),
  S1y = const(3/2 * #l * cos(2 * #angle)),
  S2x = const(#v4x - 3/2 * #l * sin(2 * #angle)),
  S2y = const(#v4y - 3/2 * #l * cos(2 * #angle)),
  S3x = const(#v4x),
  S3y = const(#v4y),
  S4x = const(#v5x),
  S4y = const(#v5y),
  S5x = const(#S4x - 3/2 * #l * sin(#angle)),
  S5y = const(#S4y - 3/2 * #l * cos(#angle)),
  S6x = const(3/2 * #l * sin(#angle)),
  S6y = const(3/2 * #l * cos(#angle)),
  
  STile
    = { filledPolygon((0,0),(#S1x, #S1y),(#S6x, #S6y))[.15,.5,.9],
        filledPolygon((#S2x, #S2y),(#S3x, #S3y), (#S4x, #S4y),(#S5x, #S5y))[.15,.5,.9],
        filledPolygon((#S1x, #S1y),(#S2x, #S2y),(#S5x, #S5y),(#S6x, #S6y))[.45,.7,.9],
        polygon(
          (0,0),
          (#S1x, #S1y),
          (#S2x, #S2y),
          (#S3x, #S3y),
          (#S4x, #S4y),
          (#S5x, #S5y),
          (#S6x, #S6y)
        )
        },
  
  Z1x = const(#l * cos(45)),
  Z1y = const(#l * sin(45)),
  Z2x = const(.5 * sin(#angle / 2)),
  Z2y = const(.5 * cos(#angle / 2)),
  Z3x = const(#v4x + #l * cos(45 + #angle)),
  Z3y = const(#v4y - #l * sin(45 + #angle)),
  Z4x = const(#v4x),
  Z4y = const(#v4y),
  Z5x = const(#v5x),
  Z5y = const(#v5y),
  Z6x = const(#Z5x + #l * cos(45)),
  Z6y = const(#v4y - #l * sin(45)),
  Z7x = const(.5 * sin(-#angle / 2)),
  Z7y = const(.5 * cos(-#angle / 2)),
  Z8x = const(#l * cos(45 + #angle)),
  Z8y = const(#l * sin(45 + #angle)),
  
  ZTileA
    = { filledPolygon(
          (0,0),
          (#Z1x, #Z1y),
          (#Z8x, #Z8y))[.15,.5,.9],
        filledPolygon(
          (#Z1x, #Z1y),
          (#Z2x, #Z2y),
          (#Z7x, #Z7y),
          (#Z8x, #Z8y))[.45,.7,.9],
        filledPolygon(
          (#Z2x, #Z2y),
          (#Z3x, #Z3y),
          (#Z6x, #Z6y),
          (#Z7x, #Z7y))[.15,.5,.9],
        filledPolygon(
          (#Z3x, #Z3y),
          (#Z4x, #Z4y),
          (#Z5x, #Z5y),
          (#Z6x, #Z6y))[.45,.7,.9],
        polygon(
          (0,0),
          (#Z1x, #Z1y),
          (#Z2x, #Z2y),
          (#Z3x, #Z3y),
          (#Z4x, #Z4y),
          (#Z5x, #Z5y),
          (#Z6x, #Z6y),
          (#Z7x, #Z7y),
          (#Z8x, #Z8y)
        )},
  ZTileB
    = { filledPolygon(
          (0,0),
          (#Z1x, #Z1y),
          (#Z8x, #Z8y))[.45,.7,.9],
        filledPolygon(
          (#Z1x, #Z1y),
          (#Z2x, #Z2y),
          (#Z7x, #Z7y),
          (#Z8x, #Z8y))[.15,.5,.9],
        filledPolygon(
          (#Z2x, #Z2y),
          (#Z3x, #Z3y),
          (#Z6x, #Z6y),
          (#Z7x, #Z7y))[.45,.7,.9],
        filledPolygon(
          (#Z3x, #Z3y),
          (#Z4x, #Z4y),
          (#Z5x, #Z5y),
          (#Z6x, #Z6y))[.15,.5,.9],
        polygon(
          (0,0),
          (#Z1x, #Z1y),
          (#Z2x, #Z2y),
          (#Z3x, #Z3y),
          (#Z4x, #Z4y),
          (#Z5x, #Z5y),
          (#Z6x, #Z6y),
          (#Z7x, #Z7y),
          (#Z8x, #Z8y)
        )},
  
  flipY = scale(1,-1) . translate(0, 2 * #v4y),
  id = scale(1),
  left = translate(-#v4x, #v4y),
  right = translate(#v4x, #v4y),
  F = < #triangle + #triangle transformed by flipY, left, right>,
  G = < #triangle + #triangle transformed by flipY, right>,
  rot180 = rotate(180) . translate(0, 2 * #v4y),
  FR = < #STile + #STile transformed by rot180, left, right>,
  GR = < #STile + #STile transformed by rot180, right>,
  F+ = < id, flipY, left, right>,
  G+ = < id, flipY, right>,
  flipX = scale(-1,1),
  flipX = <flipX>,
  
  c0 = rotate(0 * #angle + #angle / 2 - 90),
  c1 = rotate(1 * #angle + #angle / 2 - 90),
  c2 = rotate(2 * #angle + #angle / 2 - 90),
  c3 = rotate(3 * #angle + #angle / 2 - 90),
  c4 = rotate(4 * #angle + #angle / 2 - 90),
  c5 = rotate(5 * #angle + #angle / 2 - 90),
  c6 = rotate(6 * #angle + #angle / 2 - 90),
  c7 = rotate(7 * #angle + #angle / 2 - 90),
  c8 = rotate(8 * #angle + #angle / 2 - 90),
  c9 = rotate(9 * #angle + #angle / 2 - 90),
  c10 = rotate(10 * #angle + #angle / 2 - 90),
  c11 = rotate(11 * #angle + #angle / 2 - 90),
  c12 = rotate(12 * #angle + #angle / 2 - 90),
  c13 = rotate(13 * #angle + #angle / 2 - 90),
  c14 = rotate(14 * #angle + #angle / 2 - 90),
  c15 = rotate(15 * #angle + #angle / 2 - 90),
  c16 = rotate(16 * #angle + #angle / 2 - 90),
  c17 = rotate(17 * #angle + #angle / 2 - 90),
  c18 = rotate(18 * #angle + #angle / 2 - 90),
  c19 = rotate(19 * #angle + #angle / 2 - 90),
  c20 = rotate(20 * #angle + #angle / 2 - 90),
  c21 = rotate(21 * #angle + #angle / 2 - 90),
  c22 = rotate(22 * #angle + #angle / 2 - 90),
  c23 = rotate(23 * #angle + #angle / 2 - 90),
  start = < c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14,
            c15, c16, c17, c18, c19, c20, c21, c22, c23 >,
  
  c0b = use(c0) . translate(-1,0),
  c1b = use(c1) . translate(-1,0),
  c2b = use(c2) . translate(-1,0),
  c3b = use(c3) . translate(-1,0),
  c4b = use(c4) . translate(-1,0),
  c5b = use(c5) . translate(-1,0),
  c6b = use(c6) . translate(-1,0),
  c7b = use(c7) . translate(-1,0),
  c8b = use(c8) . translate(-1,0),
  c9b = use(c9) . translate(-1,0),
  c10b = use(c10) . translate(-1,0),
  c11b = use(c11) . translate(-1,0),

  c12b = use(c12) . translate(1,0),
  c13b = use(c13) . translate(1,0),
  c14b = use(c14) . translate(1,0),
  c15b = use(c15) . translate(1,0),
  c16b = use(c16) . translate(1,0),
  c17b = use(c17) . translate(1,0),
  c18b = use(c18) . translate(1,0),
  c19b = use(c19) . translate(1,0),
  c20b = use(c20) . translate(1,0),
  c21b = use(c21) . translate(1,0),
  c22b = use(c22) . translate(1,0),
  c23b = use(c23) . translate(1,0),

  startb = < c0b, c1b, c2b, c3b, c4b, c5b, c6b, c7b, c8b, c9b, c10b, c11b,
             c12b, c13b, c14b, c15b, c16b, c17b, c18b, c19b,
             c20b, c21b, c22b, c23b >
 
 }
