// A study after the Sliding House in Suffolk (dRMM, 2009): three buildings in a row on a pair of rails, and a shell of larch
// that rides over them, so the house is closed, half open or all glass as the day asks. The proportions are approximate.
// Everything is in metres and comes from the Parameters: the shell slides, the doors of the glasshouse open, the car leaves
// the garage, and the hour moves the sun, the shadows and the light in the windows.
sfl 1.11

Parameters house {
  slide: 0.6 // 0..1 step 0.01, Shell along its rails
  doors: 0.35 // 0..1 step 0.05, Glasshouse doors
  car: 0 // 0..1 step 0.05, Car out of the garage
  hour: 16 // 6..22 step 0.5, Hour of the day
  s: 30
  x0: 200
  y0: 392
  w: 5.8
  annexX: 2
  annexL: 7
  houseX: 13
  houseL: 12
  glassX: 25
  glassL: 6
  track: 38
  shellL: 16
  travel: track - shellL - 2
  shellX: 1 + slide * travel
  shellEnd: shellX + shellL
  eave: 3
  ridge: 5.4
  shellEave: 3.5
  shellRidge: 6.1
  dusk: max(0, min(1, (hour - 17.5) / 2.5)) + max(0, min(1, (7.5 - hour) / 1.5))
  day: 1 - dusk
  turn: (hour - 13) / 7 * 1.3
  reach: 0.3 + 1.5 * ((hour - 13) / 7) * ((hour - 13) / 7)
  sunX: 0 - sin(turn) * reach * s
  sunY: cos(turn) * reach * s
  leaf: doors * 1.45
  carX: 3.2 - car * 9.4
  ground: 1012
  ss: 20
  glassCovered: max(0, min(shellEnd, glassX + glassL) - max(shellX, glassX)) / glassL
  sunArc: (hour - 6) / 16
}

Style wall {
  shape: rectangle
  fill: "#fbfaf5"
  stroke: "#141414"
  strokeWidth: 8
}

Style partition {
  stroke: "#141414"
  strokeWidth: 3.2
  fill: none
}

Style thin {
  stroke: "#55554f"
  strokeWidth: 0.7
  fill: none
}

Style hair {
  stroke: "#bdbba9"
  strokeWidth: 0.45
  fill: none
}

Style rail {
  stroke: "#141414"
  strokeWidth: 1.4
  fill: none
}

Style glass {
  stroke: "#3f7f99"
  strokeWidth: 1.1
  fill: none
}

Style axis {
  stroke: "#8a887c"
  strokeWidth: 0.5
  fill: none
  dash: "[14,4,2,4]"
}

Style furniture {
  shape: rounded_rectangle
  cornerRadius: 3
  fill: "#fbfaf5"
  stroke: "#55554f"
  strokeWidth: 0.7
}

Style room {
  fontSize: 9.5
  fontWeight: 600
  textColor: "#141414"
  textAlign: center
  letterSpacing: 0.8
}

Style note {
  fontSize: 9
  textColor: "#6b695e"
  textAlign: center
}

Style small {
  fontSize: 9.5
  textColor: "#55554f"
  textAlign: left
  letterSpacing: 0.6
}

Style measure {
  stroke: "#55554f"
  strokeWidth: 0.6
  textColor: "#141414"
  fontSize: 9.5
}

Style larchLine {
  stroke: "#9c7440"
  strokeWidth: 0.5
  fill: none
}

Template tree {
  crown: 22
  Shape shade {
    layout {
      position: x - crown + 5, y - crown + 6
      size: crown * 2, crown * 2
    }
    style {
      shape: circle
      fill: "rgba(60, 70, 40, 0.10)"
      stroke: none
    }
  }
  Shape leaves {
    layout {
      position: x - crown, y - crown
      size: crown * 2, crown * 2
    }
    style {
      shape: circle
      fill: "#dbe2c6"
      stroke: "#8fa07a"
      strokeWidth: 0.7
    }
  }
  Shape heart {
    layout {
      position: x - crown * 0.42, y - crown * 0.42
      size: crown * 0.84, crown * 0.84
    }
    style {
      shape: circle
      fill: "none"
      stroke: "#8fa07a"
      strokeWidth: 0.5
    }
  }
  Shape trunk {
    layout {
      position: x - 1.6, y - 1.6
      size: 3.2, 3.2
    }
    style {
      shape: circle
      fill: "#6f7d5c"
      stroke: none
    }
  }
}

Template bed {
  Shape frame : furniture {
    layout {
      position: x, y
      size: 1.8 * s, 2.1 * s
    }
  }
  Shape pillowA : furniture {
    layout {
      position: x + 0.12 * s, y + 0.12 * s
      size: 0.72 * s, 0.42 * s
    }
  }
  Shape pillowB : furniture {
    layout {
      position: x + 0.96 * s, y + 0.12 * s
      size: 0.72 * s, 0.42 * s
    }
  }
  Path sheet : thin {
    points: [[x, y + 0.72 * s], [x + 1.8 * s, y + 0.72 * s]]
  }
}

Template chair {
  Shape seat : furniture {
    layout {
      position: x, y
      size: 0.46 * s, 0.46 * s
    }
  }
}

Template lounger {
  Shape pad : furniture {
    layout {
      position: x, y
      size: 0.72 * s, 1.9 * s
    }
  }
  Path head : thin {
    points: [[x, y + 0.5 * s], [x + 0.72 * s, y + 0.5 * s]]
  }
}

Template plant {
  size: 14
  Shape pot {
    layout {
      position: x - size / 2, y - size / 2
      size: size, size
    }
    style {
      shape: circle
      fill: "#cfe0c2"
      stroke: "#6f8f66"
      strokeWidth: 0.7
    }
  }
  Path leafA {
    points: [[x - size * 0.34, y], [x + size * 0.34, y]]
    style {
      stroke: "#6f8f66"
      strokeWidth: 0.6
      fill: none
    }
  }
  Path leafB {
    points: [[x, y - size * 0.34], [x, y + size * 0.34]]
    style {
      stroke: "#6f8f66"
      strokeWidth: 0.6
      fill: none
    }
  }
}

// The car, seen from above, nose to the west.
Template vehicle {
  Shape body {
    layout {
      position: x, y
      size: 4.4 * s, 1.85 * s
    }
    style {
      shape: rounded_rectangle
      cornerRadius: 16
      fill: "#e9e7df"
      stroke: "#141414"
      strokeWidth: 1
    }
  }
  Shape cabin {
    layout {
      position: x + 1.25 * s, y + 0.2 * s
      size: 2.1 * s, 1.45 * s
    }
    style {
      shape: rounded_rectangle
      cornerRadius: 9
      fill: "#c9d6da"
      stroke: "#141414"
      strokeWidth: 0.7
    }
  }
  Path hood : thin {
    points: [[x + 0.95 * s, y + 0.25 * s], [x + 0.95 * s, y + 1.6 * s]]
  }
}

// A person in the elevation, to read the heights by.
Template person {
  Shape head {
    layout {
      position: x - 0.13 * s, y - 1.75 * s
      size: 0.26 * s, 0.26 * s
    }
    style {
      shape: circle
      fill: "#141414"
      stroke: none
    }
  }
  Path body {
    points: [[x - 0.19 * s, y], [x - 0.24 * s, y - 1.42 * s], [x + 0.24 * s, y - 1.42 * s], [x + 0.19 * s, y]]
    closed: true
    style {
      fill: "#141414"
      stroke: none
    }
  }
}

// A window in the elevation: dark by day, lit as the evening comes.
Template lit {
  wide: 1.2
  high: 1.4
  Shape pane {
    layout {
      position: x, y
      size: wide * s, high * s
    }
    style {
      shape: rectangle
      fill: "#2b3138"
      stroke: "#141414"
      strokeWidth: 0.8
    }
  }
  Shape light {
    layout {
      position: x, y
      size: wide * s, high * s
    }
    style {
      shape: rectangle
      fill: "rgba(255, 210, 122, " + dusk + ")"
      stroke: none
    }
  }
}

Model sliding_house {
  Screen sheet {
    clip: true
    style {
      fill: "#f6f5ef"
    }
    layout {
      position: 0, 0
      size: 1600, 1210
    }

    // ---------------------------------------------------------------- the land

    Path meadowA {
      points: [[60, 150], [1540, 150], [1540, 690], [60, 690]]
      closed: true
      style {
        stroke: "#c8d0b2"
        strokeWidth: 0.7
        fill: none
        cornerRadius: 120
      }
    }
    Path meadowB {
      points: [[110, 190], [1490, 190], [1490, 660], [110, 660]]
      closed: true
      style {
        stroke: "#c8d0b2"
        strokeWidth: 0.7
        fill: "#f1f1e6"
        cornerRadius: 90
      }
    }

    // The drive of gravel, from the lane in the west to the garage.
    Path drive {
      points: [[0, y0 - 5.1 * s], [x0 + 2 * s, y0 - 5.1 * s], [x0 + 2 * s, y0 - 2.5 * s], [0, y0 - 2.5 * s]]
      closed: true
      style {
        fill: "#e2dfd2"
        stroke: "#bdbba9"
        strokeWidth: 0.6
      }
    }
    Repeat gravel {
      columns: 22
      rows: 4
      Shape stone {
        layout {
          position: 10 + col * 11.6 + 4 * sin(row * 2.3 + col), y0 - 4.9 * s + row * 18 + 3 * sin(col * 1.7)
          size: 1.6, 1.6
        }
        style {
          shape: circle
          fill: "#a9a696"
          stroke: none
        }
      }
    }

    // The deck of timber along the north side, and the paved terrace at the end of the rails.
    Shape deck {
      layout {
        position: x0 + 12 * s, y0 + 6.9 * s
        size: 19.5 * s, 2.4 * s
      }
      style {
        shape: rectangle
        fill: "#e6d9bf"
        stroke: "#8a7a55"
        strokeWidth: 0.7
      }
    }
    Repeat deckBoards {
      count: 64
      Path board {
        points: [[x0 + (12.3 + col * 0.3) * s, y0 + 6.9 * s], [x0 + (12.3 + col * 0.3) * s, y0 + 9.3 * s]]
        style {
          stroke: "#b9a67c"
          strokeWidth: 0.4
          fill: none
        }
      }
    }
    Shape terrace {
      layout {
        position: x0 + 31.3 * s, y0 - 0.2 * s
        size: 5.6 * s, 6.2 * s
      }
      style {
        shape: rectangle
        fill: "#eceadf"
        stroke: "#bdbba9"
        strokeWidth: 0.6
      }
    }
    Repeat terraceAcross {
      count: 6
      Path slabA : hair {
        points: [[x0 + (32.1 + col * 0.8) * s, y0 - 0.2 * s], [x0 + (32.1 + col * 0.8) * s, y0 + 6 * s]]
      }
    }
    Repeat terraceDown {
      count: 7
      Path slabB : hair {
        points: [[x0 + 31.3 * s, y0 + (0.6 + col * 0.8) * s], [x0 + 36.9 * s, y0 + (0.6 + col * 0.8) * s]]
      }
    }

    // Trees: a row to the south, a copse in the east, a few by the lane.
    Repeat treesSouth {
      count: 9
      Use southTree : tree {
        at: 620 + col * 104 + 18 * sin(col * 2.1), 196 + 16 * sin(col * 1.3 + 1)
        crown: 20 + 7 * sin(col * 1.9) * sin(col * 1.9)
      }
    }
    Repeat treesEast {
      count: 6
      Use eastTree : tree {
        at: 1440 + 44 * sin(col * 2.6), 262 + col * 68
        crown: 22 + 9 * sin(col * 1.4) * sin(col * 1.4)
      }
    }
    Repeat treesLane {
      count: 3
      Use laneTree : tree {
        at: 96 + col * 22 * sin(col + 1), 520 + col * 62
        crown: 24 + col * 3
      }
    }

    // ---------------------------------------------------------------- the rails

    Repeat sleepers {
      count: 75
      Path sleeper {
        points: [[x0 + (0.6 + col * 0.5) * s, y0 - 0.62 * s], [x0 + (0.6 + col * 0.5) * s, y0 - 0.22 * s]]
        style {
          stroke: "#8a887c"
          strokeWidth: 0.9
          fill: none
        }
      }
    }
    Repeat sleepersNorth {
      count: 75
      Path sleeperN {
        points: [[x0 + (0.6 + col * 0.5) * s, y0 + (w + 0.22) * s], [x0 + (0.6 + col * 0.5) * s, y0 + (w + 0.62) * s]]
        style {
          stroke: "#8a887c"
          strokeWidth: 0.9
          fill: none
        }
      }
    }
    Path railSouth : rail {
      points: [[x0 + 0.4 * s, y0 - 0.42 * s], [x0 + (track - 0.4) * s, y0 - 0.42 * s]]
    }
    Path railNorth : rail {
      points: [[x0 + 0.4 * s, y0 + (w + 0.42) * s], [x0 + (track - 0.4) * s, y0 + (w + 0.42) * s]]
    }
    Repeat buffers {
      columns: 2
      rows: 2
      Shape buffer {
        layout {
          position: x0 + (0.25 + col * (track - 0.8)) * s, y0 + (0 - 0.62 + row * (w + 0.84)) * s
          size: 0.3 * s, 0.4 * s
        }
        style {
          shape: rectangle
          fill: "#141414"
          stroke: none
        }
      }
    }

    // ---------------------------------------------------------------- shadows, by the hour

    Shape shadowShell {
      layout {
        position: x0 + shellX * s + sunX * 2, y0 - 0.75 * s + sunY * 2
        size: shellL * s, (w + 1.5) * s
      }
      style {
        shape: rectangle
        fill: "rgba(20, 22, 18, " + day * 0.17 + ")"
        stroke: none
      }
    }
    Shape shadowAnnexe {
      layout {
        position: x0 + annexX * s + sunX * 1.7, y0 + sunY * 1.7
        size: annexL * s, w * s
      }
      style {
        shape: rectangle
        fill: "rgba(20, 22, 18, " + day * 0.15 + ")"
        stroke: none
      }
    }
    Shape shadowHouse {
      layout {
        position: x0 + houseX * s + sunX * 1.7, y0 + sunY * 1.7
        size: houseL * s, w * s
      }
      style {
        shape: rectangle
        fill: "rgba(20, 22, 18, " + day * 0.15 + ")"
        stroke: none
      }
    }
    Shape shadowGarage {
      layout {
        position: x0 + 2 * s + sunX * 1.5, y0 - 7 * s + sunY * 1.5
        size: 6.5 * s, 5.4 * s
      }
      style {
        shape: rectangle
        fill: "rgba(20, 22, 18, " + day * 0.15 + ")"
        stroke: none
      }
    }

    // ---------------------------------------------------------------- the garage, off the line, and the car

    Shape garage : wall {
      layout {
        position: x0 + 2 * s, y0 - 7 * s
        size: 6.5 * s, 5.4 * s
      }
    }
    Shape garageGate {
      layout {
        position: x0 + 2 * s - 5, y0 - 5.3 * s
        size: 10, 2.9 * s
      }
      style {
        shape: rectangle
        fill: "#fbfaf5"
        stroke: none
      }
    }
    Path garageGateLine : axis {
      points: [[x0 + 2 * s, y0 - 5.3 * s], [x0 + 2 * s, y0 - 2.4 * s]]
    }
    Shape bench {
      layout {
        position: x0 + 7.2 * s, y0 - 6.7 * s
        size: 1 * s, 4.8 * s
      }
      style {
        shape: rectangle
        fill: "#fbfaf5"
        stroke: "#55554f"
        strokeWidth: 0.7
      }
    }
    Text garageLabel : room {
      text: "GARAGE"
      layout {
        position: x0 + 3.2 * s, y0 - 2.5 * s
        size: 4 * s, 12
      }
    }
    Use carNow : vehicle {
      at: x0 + carX * s, y0 - 4.8 * s
    }

    // ---------------------------------------------------------------- the annexe

    Shape annexe : wall {
      layout {
        position: x0 + annexX * s, y0
        size: annexL * s, w * s
      }
    }
    Path annexeBath : partition {
      points: [[x0 + (annexX + 4.7) * s, y0], [x0 + (annexX + 4.7) * s, y0 + 3.4 * s], [x0 + (annexX + annexL) * s, y0 + 3.4 * s]]
    }
    Use annexeBed : bed {
      at: x0 + (annexX + 0.6) * s, y0 + 0.5 * s
    }
    Shape annexeDesk : furniture {
      layout {
        position: x0 + (annexX + 0.5) * s, y0 + 4.3 * s
        size: 2.2 * s, 0.7 * s
      }
    }
    Shape tub : furniture {
      layout {
        position: x0 + (annexX + 5) * s, y0 + 0.4 * s
        size: 1.7 * s, 0.8 * s
      }
      style {
        cornerRadius: 10
      }
    }
    Shape basin : furniture {
      layout {
        position: x0 + (annexX + 5.1) * s, y0 + 2.4 * s
        size: 0.7 * s, 0.6 * s
      }
    }
    Text annexeLabel : room {
      text: "ANNEXE"
      layout {
        position: x0 + (annexX + 1) * s, y0 + 3.2 * s
        size: 3.4 * s, 12
      }
    }
    Text annexeArea : note {
      text: "" + round(annexL * w) + " m²"
      layout {
        position: x0 + (annexX + 1) * s, y0 + 3.2 * s + 13
        size: 3.4 * s, 11
      }
    }

    Text courtLabel : room {
      text: "COURT"
      layout {
        position: x0 + 9.3 * s, y0 + 2.4 * s
        size: 3.4 * s, 12
      }
    }
    Use courtPlantA : plant {
      at: x0 + 9.8 * s, y0 + 0.8 * s
      size: 22
    }
    Use courtPlantB : plant {
      at: x0 + 12 * s, y0 + 5 * s
      size: 18
    }

    // ---------------------------------------------------------------- the house

    Shape home : wall {
      layout {
        position: x0 + houseX * s, y0
        size: houseL * s, w * s
      }
    }
    Path homeCore : partition {
      points: [[x0 + (houseX + 4.4) * s, y0], [x0 + (houseX + 4.4) * s, y0 + 2.1 * s], [x0 + (houseX + 6.3) * s, y0 + 2.1 * s], [x0 + (houseX + 6.3) * s, y0]]
    }
    Shape counter : furniture {
      layout {
        position: x0 + (houseX + 0.4) * s, y0 + 0.35 * s
        size: 3.6 * s, 0.65 * s
      }
    }
    Shape hob : furniture {
      layout {
        position: x0 + (houseX + 1.2) * s, y0 + 0.42 * s
        size: 0.8 * s, 0.5 * s
      }
    }
    Shape island : furniture {
      layout {
        position: x0 + (houseX + 0.9) * s, y0 + 1.9 * s
        size: 2.6 * s, 0.9 * s
      }
    }
    Shape diningTable : furniture {
      layout {
        position: x0 + (houseX + 0.9) * s, y0 + 3.9 * s
        size: 2.6 * s, 1 * s
      }
    }
    Repeat diningChairs {
      columns: 3
      rows: 2
      Use diner : chair {
        at: x0 + (houseX + 1.15 + col * 0.85) * s, y0 + (3.36 + row * 1.62) * s
      }
    }
    Repeat stairs {
      count: 9
      Path tread : thin {
        points: [[x0 + (houseX + 6.6 + col * 0.26) * s, y0 + 0.3 * s], [x0 + (houseX + 6.6 + col * 0.26) * s, y0 + 1.5 * s]]
      }
    }
    Path stairsFrame : thin {
      points: [[x0 + (houseX + 6.5) * s, y0 + 0.3 * s], [x0 + (houseX + 8.9) * s, y0 + 0.3 * s], [x0 + (houseX + 8.9) * s, y0 + 1.5 * s], [x0 + (houseX + 6.5) * s, y0 + 1.5 * s]]
      closed: true
    }
    Shape sofa : furniture {
      layout {
        position: x0 + (houseX + 7.4) * s, y0 + 4.5 * s
        size: 2.8 * s, 0.9 * s
      }
      style {
        cornerRadius: 7
      }
    }
    Shape sofaSide : furniture {
      layout {
        position: x0 + (houseX + 10.3) * s, y0 + 2.5 * s
        size: 0.9 * s, 2.1 * s
      }
      style {
        cornerRadius: 7
      }
    }
    Shape coffeeTable : furniture {
      layout {
        position: x0 + (houseX + 8) * s, y0 + 3 * s
        size: 1.5 * s, 0.8 * s
      }
    }
    Shape stove {
      layout {
        position: x0 + (houseX + 9.4) * s, y0 + 0.4 * s
        size: 0.7 * s, 0.7 * s
      }
      style {
        shape: circle
        fill: "#141414"
        stroke: none
      }
    }
    Text kitchenLabel : room {
      text: "KITCHEN AND DINING"
      layout {
        position: x0 + (houseX + 0.4) * s, y0 + 2.88 * s
        size: 3.6 * s, 12
      }
    }
    Text livingLabel : room {
      text: "LIVING"
      layout {
        position: x0 + (houseX + 6.6) * s, y0 + 2.2 * s
        size: 3.4 * s, 12
      }
    }
    Text homeArea : note {
      text: "" + round(houseL * w) + " m²"
      layout {
        position: x0 + (houseX + 6.6) * s, y0 + 2.2 * s + 13
        size: 3.4 * s, 11
      }
    }

    // Openings: where a wall is glass, the black gives way to two fine lines.
    Repeat windowsSouth {
      count: 3
      Shape gapS {
        layout {
          position: x0 + (houseX + 1 + col * 3.9) * s, y0 - 5
          size: 2.2 * s, 10
        }
        style {
          shape: rectangle
          fill: "#fbfaf5"
          stroke: none
        }
      }
    }
    Repeat windowsSouthGlass {
      count: 3
      Path paneS : glass {
        points: [[x0 + (houseX + 1 + col * 3.9) * s, y0], [x0 + (houseX + 3.2 + col * 3.9) * s, y0]]
      }
    }
    Repeat windowsNorth {
      count: 3
      Shape gapN {
        layout {
          position: x0 + (houseX + 1 + col * 3.9) * s, y0 + w * s - 5
          size: 2.6 * s, 10
        }
        style {
          shape: rectangle
          fill: "#fbfaf5"
          stroke: none
        }
      }
    }
    Repeat windowsNorthGlass {
      count: 3
      Path paneN : glass {
        points: [[x0 + (houseX + 1 + col * 3.9) * s, y0 + w * s], [x0 + (houseX + 3.6 + col * 3.9) * s, y0 + w * s]]
      }
    }
    Shape annexeGap {
      layout {
        position: x0 + (annexX + 1.2) * s, y0 + w * s - 5
        size: 2.4 * s, 10
      }
      style {
        shape: rectangle
        fill: "#fbfaf5"
        stroke: none
      }
    }
    Path annexePane : glass {
      points: [[x0 + (annexX + 1.2) * s, y0 + w * s], [x0 + (annexX + 3.6) * s, y0 + w * s]]
    }
    Shape passage {
      layout {
        position: x0 + (houseX + houseL) * s - 5, y0 + 1.6 * s
        size: 10, 2.6 * s
      }
      style {
        shape: rectangle
        fill: "#fbfaf5"
        stroke: none
      }
    }

    // ---------------------------------------------------------------- the glasshouse, and its doors

    Shape glasshouse {
      layout {
        position: x0 + glassX * s, y0
        size: glassL * s, w * s
      }
      style {
        shape: rectangle
        fill: "rgba(170, 205, 215, 0.28)"
        stroke: "#3f7f99"
        strokeWidth: 2.2
      }
    }
    Repeat mullions {
      count: 5
      Path mullionS : glass {
        points: [[x0 + (glassX + 1 + col) * s, y0 - 3], [x0 + (glassX + 1 + col) * s, y0 + 3]]
      }
    }
    Repeat mullionsNorth {
      count: 5
      Path mullionN : glass {
        points: [[x0 + (glassX + 1 + col) * s, y0 + w * s - 3], [x0 + (glassX + 1 + col) * s, y0 + w * s + 3]]
      }
    }
    Use loungerA : lounger {
      at: x0 + (glassX + 0.8) * s, y0 + 0.6 * s
    }
    Use loungerB : lounger {
      at: x0 + (glassX + 1.9) * s, y0 + 0.6 * s
    }
    Shape gardenTable {
      layout {
        position: x0 + (glassX + 3.4) * s, y0 + 3.5 * s
        size: 1.2 * s, 1.2 * s
      }
      style {
        shape: circle
        fill: "#fbfaf5"
        stroke: "#55554f"
        strokeWidth: 0.7
      }
    }
    Repeat gardenChairs {
      count: 4
      Use gardenChair : chair {
        at: x0 + (glassX + 3.77 + 1.05 * cos(col * 1.5708)) * s, y0 + (3.87 + 1.05 * sin(col * 1.5708)) * s
      }
    }
    Repeat glassPlants {
      count: 4
      Use glassPlant : plant {
        at: x0 + (glassX + 0.7 + col * 1.5) * s, y0 + 5.2 * s
        size: 14 + 5 * sin(col * 2.2) * sin(col * 2.2)
      }
    }
    Text glassLabel : room {
      text: "GLASSHOUSE"
      layout {
        position: x0 + (glassX + 0.05) * s, y0 + 2.9 * s
        size: 2.6 * s, 12
      }
    }

    // The two leaves of the door in the east wall slide apart; the gap between them is the way out to the terrace.
    Shape doorGap {
      layout {
        position: x0 + (glassX + glassL) * s - 4, y0 + (2.9 - leaf) * s
        size: 8, leaf * 2 * s
      }
      style {
        shape: rectangle
        fill: "#f6f5ef"
        stroke: none
      }
    }
    Path doorLeafA {
      points: [[x0 + (glassX + glassL) * s + 4, y0 + (1.45 - leaf) * s], [x0 + (glassX + glassL) * s + 4, y0 + (2.9 - leaf) * s]]
      style {
        stroke: "#1f5f78"
        strokeWidth: 2.6
        fill: none
      }
    }
    Path doorLeafB {
      points: [[x0 + (glassX + glassL) * s + 4, y0 + (2.9 + leaf) * s], [x0 + (glassX + glassL) * s + 4, y0 + (4.35 + leaf) * s]]
      style {
        stroke: "#1f5f78"
        strokeWidth: 2.6
        fill: none
      }
    }
    Text doorLabel : small {
      text: "" + round(leaf * 2 * 10) / 10 + " m open"
      layout {
        position: x0 + (glassX + glassL + 0.5) * s, y0 + 2.75 * s
        size: 90, 12
      }
    }

    // ---------------------------------------------------------------- the shell of larch, over whatever it stands on

    Shape shell {
      layout {
        position: x0 + shellX * s, y0 - 0.6 * s
        size: shellL * s, (w + 1.2) * s
      }
      style {
        shape: rectangle
        fill: "rgba(205, 165, 105, 0.34)"
        stroke: "#9c7440"
        strokeWidth: 9
      }
    }
    Repeat shellBoards {
      count: 31
      Path shellBoard : larchLine {
        points: [[x0 + (shellX + 0.5 + col * 0.5) * s, y0 - 0.45 * s], [x0 + (shellX + 0.5 + col * 0.5) * s, y0 + (w + 0.45) * s]]
      }
    }
    Path shellRidge {
      points: [[x0 + shellX * s, y0 + w / 2 * s], [x0 + shellEnd * s, y0 + w / 2 * s]]
      style {
        stroke: "#7d5a2c"
        strokeWidth: 1.1
        fill: none
        dash: "[10,5]"
      }
    }
    Repeat shellLights {
      count: 3
      Shape skylight {
        layout {
          position: x0 + (shellX + 2 + col * 5) * s, y0 + 0.9 * s
          size: 2.2 * s, 1.3 * s
        }
        style {
          shape: rectangle
          fill: "rgba(170, 205, 215, 0.55)"
          stroke: "#7d5a2c"
          strokeWidth: 1
        }
      }
    }
    Text shellLabel {
      text: "SHELL OF LARCH  ·  " + shellL + " m  ·  20 t"
      layout {
        position: x0 + shellX * s, y0 + (w + 1.35) * s
        size: shellL * s, 13
      }
      style {
        fontSize: 10
        fontWeight: 700
        textColor: "#5e431f"
        textAlign: center
        letterSpacing: 1.6
      }
    }

    // How far the shell has gone, measured as it moves.
    Dimension shellPlace : measure {
      text: "" + round(shellX * 10) / 10
      start: x0, y0 - 0.62 * s
      end: x0 + shellX * s, y0 - 0.62 * s
      offset: 15
    }
    Dimension shellLength : measure {
      text: "" + shellL
      start: x0 + shellX * s, y0 - 0.62 * s
      end: x0 + shellEnd * s, y0 - 0.62 * s
      offset: 15
    }

    // ---------------------------------------------------------------- axes and measures

    Repeat axes {
      count: 6
      ax: when(col == 0, annexX, when(col == 1, annexX + annexL, when(col == 2, houseX, when(col == 3, glassX, when(col == 4, glassX + glassL, track - 1)))))
      Path axisLine : axis {
        points: [[x0 + ax * s, y0 - 1.3 * s], [x0 + ax * s, ground]]
      }
    }
    Repeat axisMarks {
      count: 6
      bx: when(col == 0, annexX, when(col == 1, annexX + annexL, when(col == 2, houseX, when(col == 3, glassX, when(col == 4, glassX + glassL, track - 1)))))
      Shape bubble {
        layout {
          position: x0 + bx * s - 10, y0 + 11.2 * s
          size: 20, 20
        }
        style {
          shape: circle
          fill: "#f6f5ef"
          stroke: "#141414"
          strokeWidth: 0.8
        }
      }
    }
    Repeat axisLetters {
      count: 6
      cx: when(col == 0, annexX, when(col == 1, annexX + annexL, when(col == 2, houseX, when(col == 3, glassX, when(col == 4, glassX + glassL, track - 1)))))
      Text letter {
        text: "" + (col + 1)
        layout {
          position: x0 + cx * s - 10, y0 + 11.2 * s + 4
          size: 20, 12
        }
        style {
          fontSize: 9.5
          fontWeight: 600
          textColor: "#141414"
          textAlign: center
        }
      }
    }
    Dimension dAnnexe : measure {
      text: "" + annexL
      start: x0 + annexX * s, y0 + 10.5 * s
      end: x0 + (annexX + annexL) * s, y0 + 10.5 * s
      offset: 0
    }
    Dimension dCourt : measure {
      text: "" + (houseX - annexX - annexL)
      start: x0 + (annexX + annexL) * s, y0 + 10.5 * s
      end: x0 + houseX * s, y0 + 10.5 * s
      offset: 0
    }
    Dimension dHouse : measure {
      text: "" + houseL
      start: x0 + houseX * s, y0 + 10.5 * s
      end: x0 + glassX * s, y0 + 10.5 * s
      offset: 0
    }
    Dimension dGlass : measure {
      text: "" + glassL
      start: x0 + glassX * s, y0 + 10.5 * s
      end: x0 + (glassX + glassL) * s, y0 + 10.5 * s
      offset: 0
    }
    Dimension dTerrace : measure {
      text: "" + (track - 1 - glassX - glassL)
      start: x0 + (glassX + glassL) * s, y0 + 10.5 * s
      end: x0 + (track - 1) * s, y0 + 10.5 * s
      offset: 0
    }
    Dimension dWidth : measure {
      text: "" + w
      start: x0 + (track + 0.6) * s, y0
      end: x0 + (track + 0.6) * s, y0 + w * s
      offset: 0
    }

    // ---------------------------------------------------------------- the long elevation, on the same axes

    Shape sky {
      layout {
        position: 60, ground - 236
        size: 1480, 236
      }
      style {
        shape: rectangle
        fill: "rgba(22, 28, 52, " + dusk * 0.9 + ")"
        stroke: none
      }
    }
    Repeat stars {
      count: 46
      Shape star {
        layout {
          position: 80 + col * 31.5 + 12 * sin(col * 5.1), ground - 226 + 70 * sin(col * 2.7) * sin(col * 2.7) + 30 * sin(col * 1.1) * sin(col * 1.1)
          size: 1.8, 1.8
        }
        style {
          shape: circle
          fill: "rgba(255, 255, 255, " + dusk + ")"
          stroke: none
        }
      }
    }
    // The sun crosses the sheet with the hour, and stands highest at one.
    Shape sunDisc {
      layout {
        position: 90 + sunArc * 1400 - 13, ground - 60 - 160 * sin(sunArc * 3.1416) - 13
        size: 26, 26
      }
      style {
        shape: circle
        fill: when(dusk > 0.6, "#f1eedc", "#f2b233")
        stroke: when(dusk > 0.6, "#c9c6b4", "#d9941c")
        strokeWidth: 0.8
      }
    }
    Repeat elevTrees {
      count: 5
      Shape elevTree {
        layout {
          position: 96 + col * 330 + 40 * sin(col * 2), ground - 96 - 30 * sin(col * 1.6) * sin(col * 1.6)
          size: 76 + 30 * sin(col * 1.6) * sin(col * 1.6), 76 + 30 * sin(col * 1.6) * sin(col * 1.6)
        }
        style {
          shape: circle
          fill: "#e2e7d2"
          stroke: "#8fa07a"
          strokeWidth: 0.7
        }
      }
    }
    // By night the trees stand dark against the sky.
    Repeat elevTreesNight {
      count: 5
      Shape elevTreeNight {
        layout {
          position: 96 + col * 330 + 40 * sin(col * 2), ground - 96 - 30 * sin(col * 1.6) * sin(col * 1.6)
          size: 76 + 30 * sin(col * 1.6) * sin(col * 1.6), 76 + 30 * sin(col * 1.6) * sin(col * 1.6)
        }
        style {
          shape: circle
          fill: "rgba(22, 28, 52, " + dusk * 0.82 + ")"
          stroke: none
        }
      }
    }
    Repeat elevTrunks {
      count: 5
      Path elevTrunk : thin {
        points: [[134 + col * 330 + 40 * sin(col * 2) + 15 * sin(col * 1.6) * sin(col * 1.6), ground - 22], [134 + col * 330 + 40 * sin(col * 2) + 15 * sin(col * 1.6) * sin(col * 1.6), ground]]
      }
    }

    // The annexe and the house, red; the glasshouse, all panes.
    Shape elevAnnexeRoof {
      layout {
        position: x0 + annexX * s, ground - ridge * s
        size: annexL * s, (ridge - eave) * s
      }
      style {
        shape: rectangle
        fill: "#8e3327"
        stroke: "#141414"
        strokeWidth: 0.8
      }
    }
    Shape elevAnnexe {
      layout {
        position: x0 + annexX * s, ground - eave * s
        size: annexL * s, eave * s
      }
      style {
        shape: rectangle
        fill: "#a8402f"
        stroke: "#141414"
        strokeWidth: 0.8
      }
    }
    Use annexeWindow : lit {
      at: x0 + (annexX + 1.2) * s, ground - 2.4 * s
      wide: 2.4
      high: 1.5
    }
    Shape elevHouseRoof {
      layout {
        position: x0 + houseX * s, ground - ridge * s
        size: houseL * s, (ridge - eave) * s
      }
      style {
        shape: rectangle
        fill: "#8e3327"
        stroke: "#141414"
        strokeWidth: 0.8
      }
    }
    Shape elevHouse {
      layout {
        position: x0 + houseX * s, ground - eave * s
        size: houseL * s, eave * s
      }
      style {
        shape: rectangle
        fill: "#a8402f"
        stroke: "#141414"
        strokeWidth: 0.8
      }
    }
    Repeat houseWindows {
      count: 3
      Use houseWindow : lit {
        at: x0 + (houseX + 1 + col * 3.9) * s, ground - 2.6 * s
        wide: 2.6
        high: 2
      }
    }
    Repeat roofWindows {
      count: 2
      Use roofWindow : lit {
        at: x0 + (houseX + 2.4 + col * 5.6) * s, ground - 4.7 * s
        wide: 1.4
        high: 0.9
      }
    }
    Shape elevGlass {
      layout {
        position: x0 + glassX * s, ground - ridge * s
        size: glassL * s, ridge * s
      }
      style {
        shape: rectangle
        fill: "#dcebef"
        stroke: "#3f7f99"
        strokeWidth: 1
      }
    }
    Shape elevGlassLight {
      layout {
        position: x0 + glassX * s, ground - ridge * s
        size: glassL * s, ridge * s
      }
      style {
        shape: rectangle
        fill: "rgba(255, 210, 122, " + dusk * 0.8 + ")"
        stroke: none
      }
    }
    Repeat elevMullions {
      count: 5
      Path elevMullion : glass {
        points: [[x0 + (glassX + 1 + col) * s, ground - ridge * s], [x0 + (glassX + 1 + col) * s, ground]]
      }
    }
    Path elevGlassEave : glass {
      points: [[x0 + glassX * s, ground - eave * s], [x0 + (glassX + glassL) * s, ground - eave * s]]
    }

    // The shell, in front of whatever it covers, on its wheels.
    Shape elevShellRoof {
      layout {
        position: x0 + shellX * s, ground - shellRidge * s
        size: shellL * s, (shellRidge - shellEave) * s
      }
      style {
        shape: rectangle
        fill: "#c39a5f"
        stroke: "#5e431f"
        strokeWidth: 1
      }
    }
    Shape elevShell {
      layout {
        position: x0 + shellX * s, ground - shellEave * s
        size: shellL * s, (shellEave - 0.12) * s
      }
      style {
        shape: rectangle
        fill: "#d4b07a"
        stroke: "#5e431f"
        strokeWidth: 1
      }
    }
    Repeat elevShellBoards {
      count: 63
      Path elevBoard : larchLine {
        points: [[x0 + (shellX + 0.25 + col * 0.25) * s, ground - shellRidge * s + 1], [x0 + (shellX + 0.25 + col * 0.25) * s, ground - 0.14 * s]]
      }
    }
    Repeat shellOpenings {
      count: 3
      Use shellOpening : lit {
        at: x0 + (shellX + 1.6 + col * 5) * s, ground - 2.7 * s
        wide: 2.8
        high: 2.1
      }
    }
    Repeat wheels {
      count: 6
      Shape wheel {
        layout {
          position: x0 + (shellX + 0.6 + col * 2.96) * s - 4, ground - 8
          size: 8, 8
        }
        style {
          shape: circle
          fill: "#141414"
          stroke: none
        }
      }
    }

    Path groundLine : rail {
      points: [[60, ground], [1540, ground]]
    }
    Repeat earth {
      count: 72
      Path hatch : hair {
        points: [[62 + col * 20.6, ground + 14], [76 + col * 20.6, ground]]
      }
    }
    Use walker : person {
      at: x0 + 11 * s, ground
    }
    Use gardener : person {
      at: x0 + 34.2 * s, ground
    }
    Text elevLabel : small {
      text: "NORTH ELEVATION, ON THE AXES OF THE PLAN"
      layout {
        position: 64, ground + 24
        size: 420, 12
      }
    }

    // ---------------------------------------------------------------- the section across: a house inside a house

    Path sectionShell {
      points: [[1426, ground - 0.14 * ss], [1426, ground - shellEave * ss], [1426 + (w / 2 + 0.75) * ss, ground - shellRidge * ss], [1426 + (w + 1.5) * ss, ground - shellEave * ss], [1426 + (w + 1.5) * ss, ground - 0.14 * ss]]
      style {
        fill: "#d4b07a"
        stroke: "#5e431f"
        strokeWidth: 1
      }
      closed: true
    }
    Path sectionAir {
      points: [[1426 + 0.35 * ss, ground - 0.14 * ss], [1426 + 0.35 * ss, ground - (shellEave - 0.2) * ss], [1426 + (w / 2 + 0.75) * ss, ground - (shellRidge - 0.42) * ss], [1426 + (w + 1.15) * ss, ground - (shellEave - 0.2) * ss], [1426 + (w + 1.15) * ss, ground - 0.14 * ss]]
      style {
        fill: "#f6f5ef"
        stroke: "#5e431f"
        strokeWidth: 0.6
      }
      closed: true
    }
    Path sectionHouse {
      points: [[1426 + 0.75 * ss, ground], [1426 + 0.75 * ss, ground - eave * ss], [1426 + (w / 2 + 0.75) * ss, ground - ridge * ss], [1426 + (w + 0.75) * ss, ground - eave * ss], [1426 + (w + 0.75) * ss, ground]]
      style {
        fill: "#a8402f"
        stroke: "#141414"
        strokeWidth: 1
      }
      closed: true
    }
    Shape sectionRoom {
      layout {
        position: 1426 + 1.05 * ss, ground - (eave - 0.3) * ss
        size: (w - 0.6) * ss, (eave - 0.3) * ss
      }
      style {
        shape: rectangle
        fill: "rgba(255, 210, 122, " + (0.25 + dusk * 0.75) + ")"
        stroke: "#141414"
        strokeWidth: 0.6
      }
    }
    Repeat sectionWheels {
      count: 2
      Shape sectionWheel {
        layout {
          position: 1426 + (0.02 + col * (w + 1.15)) * ss, ground - 6
          size: 6, 6
        }
        style {
          shape: circle
          fill: "#141414"
          stroke: none
        }
      }
    }
    Text sectionLabel : small {
      text: "SECTION  ·  ridge " + shellRidge + " m"
      layout {
        position: 1380, ground + 24
        size: 220, 12
      }
    }

    // ---------------------------------------------------------------- north, scale and the title of the sheet

    Shape northRing {
      layout {
        position: 1498, 66
        size: 44, 44
      }
      style {
        shape: circle
        fill: "none"
        stroke: "#141414"
        strokeWidth: 0.9
      }
    }
    Path northNeedle {
      points: [[1520, 104], [1512, 82], [1520, 88], [1528, 82]]
      closed: true
      style {
        fill: "#141414"
        stroke: none
      }
    }
    Text northLetter {
      text: "N"
      layout {
        position: 1510, 112
        size: 20, 14
      }
      style {
        fontSize: 11
        fontWeight: 700
        textColor: "#141414"
        textAlign: center
      }
    }

    Text title {
      text: "SLIDING HOUSE"
      layout {
        position: 62, 46
        size: 640, 46
      }
      style {
        fontSize: 36
        fontWeight: 700
        textColor: "#141414"
        textAlign: left
        letterSpacing: 5
      }
    }
    Text subtitle {
      text: "Study after the Sliding House in Suffolk, by dRMM, 2009. Proportions approximate."
      layout {
        position: 64, 96
        size: 700, 16
      }
      style {
        fontSize: 12
        textColor: "#55554f"
        textAlign: left
      }
    }
    Text state {
      text: "The shell stands over " + when(shellEnd <= houseX + 3, "the annexe and the court", when(shellX >= glassX - 5, "the glasshouse and the terrace", when(shellX >= houseX - 2, "the house and the glasshouse", "the court and the house"))) + ".  The glasshouse is " + round((1 - glassCovered) * 100) + " % open to the sky."
      layout {
        position: 64, 116
        size: 900, 16
      }
      style {
        fontSize: 12
        fontWeight: 600
        textColor: "#141414"
        textAlign: left
      }
    }

    Shape titleBlock {
      layout {
        position: 1240, 1098
        size: 300, 96
      }
      style {
        shape: rectangle
        fill: "#fbfaf5"
        stroke: "#141414"
        strokeWidth: 0.9
      }
    }
    Path titleRule : thin {
      points: [[1240, 1140], [1540, 1140]]
    }
    Path titleSplit : thin {
      points: [[1390, 1140], [1390, 1194]]
    }
    Text blockTitle {
      text: "SLIDING HOUSE"
      layout {
        position: 1252, 1108
        size: 280, 16
      }
      style {
        fontSize: 13
        fontWeight: 700
        textColor: "#141414"
        textAlign: left
        letterSpacing: 2
      }
    }
    Text blockSub : small {
      text: "Ground floor plan, elevation, section"
      layout {
        position: 1252, 1125
        size: 280, 12
      }
    }
    Text blockScale : small {
      text: "Scale  1 : 100"
      layout {
        position: 1252, 1150
        size: 130, 12
      }
    }
    Text blockArea : small {
      text: "Floor  " + round((annexL + houseL + glassL) * w) + " m²"
      layout {
        position: 1252, 1170
        size: 130, 12
      }
    }
    Text blockSheet : small {
      text: "Sheet  A-101"
      layout {
        position: 1402, 1150
        size: 130, 12
      }
    }
    Text blockRails : small {
      text: "Rails  " + track + " m"
      layout {
        position: 1402, 1170
        size: 130, 12
      }
    }
    // The scale bar stands in the row of the elevation labels, between them, clear of the title block.
    Repeat scaleBar {
      count: 4
      Shape scalePart {
        layout {
          position: 1030 + col * 2.5 * s, ground + 22
          size: 2.5 * s, 6
        }
        style {
          shape: rectangle
          fill: when(col - floor(col / 2) * 2 == 0, "#141414", "#f6f5ef")
          stroke: "#141414"
          strokeWidth: 0.6
        }
      }
    }
    Repeat scaleNumbers {
      count: 3
      Text scaleNumber : small {
        text: when(col == 2, "10 m", "" + col * 5)
        layout {
          position: 1000 + col * 5 * s, ground + 32
          size: 60, 12
        }
        style {
          textAlign: center
        }
      }
    }

    // ---------------------------------------------------------------- what can be moved

    Text slideLabel {
      text: <- "Shell  " + round((1 + house.slide * 20) * 10) / 10 + " m along its rails"
      layout {
        position: 64, 1106
        size: 220, 14
      }
      style {
        fontSize: 11
        textColor: "#141414"
        textAlign: left
      }
    }
    Component slideControl {
      type: slider
      value: <-> house.slide
      min: 0
      max: 1
      layout {
        position: 64, 1124
        size: 200, 32
      }
      style {
        accent: "#9c7440"
        track: "#d2d0c6"
        step: 0.01
      }
    }
    Text doorsLabel {
      text: <- "Glasshouse doors  " + round(house.doors * 100) + " %"
      layout {
        position: 296, 1106
        size: 220, 14
      }
      style {
        fontSize: 11
        textColor: "#141414"
        textAlign: left
      }
    }
    Component doorsControl {
      type: slider
      value: <-> house.doors
      min: 0
      max: 1
      layout {
        position: 296, 1124
        size: 200, 32
      }
      style {
        accent: "#1f5f78"
        track: "#d2d0c6"
        step: 0.05
      }
    }
    Text carLabel {
      text: <- when(house.car > 0.05, "Car on the drive", "Car in the garage")
      layout {
        position: 528, 1106
        size: 220, 14
      }
      style {
        fontSize: 11
        textColor: "#141414"
        textAlign: left
      }
    }
    Component carControl {
      type: slider
      value: <-> house.car
      min: 0
      max: 1
      layout {
        position: 528, 1124
        size: 200, 32
      }
      style {
        accent: "#141414"
        track: "#d2d0c6"
        step: 0.05
      }
    }
    Text hourLabel {
      text: <- "Hour  " + house.hour + " h"
      layout {
        position: 760, 1106
        size: 220, 14
      }
      style {
        fontSize: 11
        textColor: "#141414"
        textAlign: left
      }
    }
    Component hourControl {
      type: slider
      value: <-> house.hour
      min: 6
      max: 22
      layout {
        position: 760, 1124
        size: 200, 32
      }
      style {
        accent: "#d9941c"
        track: "#d2d0c6"
        step: 0.5
      }
    }
  }
}
