Ollin

MansionDelAgua

Sheets laid one over another, each throwing its shadow on the ones under it, after Gunther Gerzso's Mansión del agua (1965).

Run
swift run --package-path Examples Example-Recreations-GuntherGerzso-MansionDelAgua
Source
Examples/Recreations/GuntherGerzso/MansionDelAgua/Sketch.swift
//  Recreation after Gunther Gerzso - Mansión del agua (Water Mansion), 1965,
//  oil on canvas, 81 x 100 cm, Blanton Museum of Art, The University of
//  Texas at Austin, gift of John and Barbara Duncan, 1971. A homage, not a
//  reproduction, and not affiliated with or endorsed by the artist's estate
//  or the museum.
//  https://artsandculture.google.com/asset/dAESFVnSqAY2Mg
//  https://bombmagazine.org/articles/gunther-gerzso/
//
//  An original Ollin interpretation written from the museum's picture of the
//  painting, from Gerzso's own account of how he worked, and from the
//  chronology in the 2003 Santa Barbara retrospective's catalog. Nothing was
//  ported: the work is oil on canvas.

import Foundation
import Ollin

/// Mansión del agua (Gunther Gerzso, 1965). A painting of sheets, one over
/// another like cut card. A long sheet lies across the top and a larger one
/// under it. Below them is a row of deep ocher panels, and pale slabs lie
/// over the lower third. It is painted in nearly one color, an olive that
/// runs from ocher to gray-green, so the depth is all in the edges. Where a
/// sheet passes under another it goes dark, darkest in a thin line right at
/// the edge and clear again a hand's width away. Toward its own free edge a
/// sheet lightens. Where no sheet reaches, the ground is black. He told
/// Rita Eder that at the back of his paintings there is a black plane.
///
/// Two things here come from his own words and from his catalog. He said
/// that his technique let him erase nothing, so everything had to be added.
/// The sketch only ever lays a sheet over what is there. The catalog's
/// chronology says he began composing with the golden section in the
/// middle of the 1960s, and the painting agrees. Its large sheet ends at
/// 0.61 to 0.62 of the height, the golden cut. Its long strip begins at
/// 0.85, the next cut below. The sheets here are laid out on those cuts.
/// The rest is read off the museum's picture: which sheet lies over which,
/// how long the shadows are, and the colors.
///
/// The seed deals one such painting: where the sheets step, which side the
/// tall strip stands on, where the panels divide. No seed is the painting
/// itself. Over one cycle of `seconds` the light drifts by `swing` degrees
/// to either side of `light`, and the shadows turn with it. Then the sheets
/// are lifted off front to back, down to the black ground with the cuts
/// ruled on it. They are laid again in their order.
///
/// Try it: `depth` is how far the sheets stand off each other. At 0 the
/// painting is pressed flat and the slits close. `slabs` is how many pale
/// slabs it has, `glow` how much a sheet lightens toward its free edge, and
/// `grain` how pitted the paint is. `guides` rules the golden cuts over the
/// finished picture. A press deals the next painting.
@main
final class MansionDelAgua: Sketch {
    /// How far each sheet stands off the one under it. It sets the length
    /// of every shadow, and 0 presses the painting flat.
    @Param(0 ... 2.5, icon: "square.stack.3d.up") var depth = 1.0
    /// Where the light comes from, in degrees left (negative) or right of
    /// straight above.
    @Param(-60 ... 60, icon: "sun.max") var light = -12.0
    /// How far the light drifts to either side over one cycle, in degrees.
    @Param(0 ... 45, icon: "arrow.left.and.right") var swing = 16.0
    /// How many pale slabs are laid last.
    @Param(0 ... 6, icon: "rectangle.stack") var slabs = 6
    /// How much a sheet lightens toward its free edge.
    @Param(0 ... 1, icon: "sunrise") var glow = 0.65
    /// How pitted and streaked the paint is.
    @Param(0 ... 1, icon: "circle.dotted") var grain = 0.7
    /// The golden cuts the sheets are laid out on, ruled over the picture.
    @Param(icon: "grid") var guides = false
    /// One cycle: the light drifts, the sheets are lifted, and laid again.
    @Param(8 ... 30, icon: "clock") var seconds = 24.0

    // The painting is 100 by 81 centimeters.
    override var canvasSize: CanvasSize { .size(1334, 1080) }
    override var loopDuration: Double? { seconds }

    // MARK: - The golden cuts

    /// The golden cut of a length, and the cuts of the cuts: 0.618, 0.382,
    /// 0.236, 0.146, 0.090, 0.056, 0.034. Each is the one before times
    /// 0.618.
    nonisolated static let cuts: [Double] = (1 ... 7).map { pow((5.0.squareRoot() - 1) / 2, Double($0)) }

    /// The lines ruled on the bare ground: each side cut at 0.382 and 0.618,
    /// and each of the three parts cut the same way again.
    nonisolated static let lattice: [Double] = {
        let a = cuts[1], b = cuts[0]
        var lines: [Double] = []
        for (from, to) in [(0.0, a), (a, b), (b, 1.0)] {
            lines += [from + (to - from) * a, from + (to - from) * b, to]
        }
        return lines.dropLast().sorted()
    }()

    // MARK: - A sheet

    /// The way a sheet is laid: from its top edge down, or in from one side.
    private enum Entry { case down, fromLeft, fromRight }

    /// One sheet of the painting. It has an outline in pixels, a paint for
    /// its tucked side, and one for its free edge. It also has a height off
    /// what is under it, and a way of being laid.
    private struct Sheet {
        var outline: [Vector2]
        var base: Color
        var lit: Color
        /// The shadow it throws, as a multiple of the unit length.
        var lift: Double
        /// The paint runs from `base` here to `lit` at `free`.
        var tucked: Vector2
        var free: Vector2
        /// How much it lightens toward every edge, not only the free one.
        var rim: Double
        var entry: Entry
        var grainSeed: Double
        var pale = false
    }

    private let ground = Color(hex: 0x16190F)
    private let lip = Color(hex: 0xC4C8A0)

    private var composition: [Sheet] = []
    private var built = (seed: Int.min, slabs: -1, width: 0.0, height: 0.0)
    private var pressed = 0

    override func mousePressed() {
        pressed += 1
    }

    // MARK: - Dealing a painting

    /// Deal one painting, as its sheets from the deepest to the nearest.
    /// Positions are parts of the width and the height until they are laid.
    /// The upper two sheets and the lower slabs each pick their own side.
    /// Half the seeds read left to right and half the other way.
    private func deal(seed: Int, slabs: Int) -> [Sheet] {
        var rng = SplitMix64(seed: UInt64(bitPattern: Int64(seed &* 1_000_003 &+ 1965)))
        func roll(_ range: ClosedRange<Double>) -> Double { Double.random(in: range, using: &rng) }
        func pick(_ options: [Double]) -> Double { options[Int.random(in: 0 ..< options.count, using: &rng)] }
        func coin(_ p: Double) -> Bool { Double.random(in: 0 ..< 1, using: &rng) < p }
        let w = width, h = height
        let c = MansionDelAgua.cuts
        // Sheets run this far past the canvas, so no edge of theirs shows there.
        let over = 0.06
        var sheets: [Sheet] = []
        var grainSeed = roll(0 ... 40)
        /// Lay a sheet. `flipped` mirrors it left to right, and `from` and
        /// `to` are the heights its paint runs between.
        func lay(_ points: [(Double, Double)], flipped: Bool, base: UInt32, lit: UInt32, lift: Double,
                 rim: Double = 0, entry: Entry = .down, pale: Bool = false, from: Double, to: Double) {
            grainSeed += 1.37
            let side: Entry = flipped ? (entry == .fromLeft ? .fromRight : entry == .fromRight ? .fromLeft : .down) : entry
            let tint = roll(-0.035 ... 0.035)
            func toned(_ hex: UInt32) -> Color {
                let color = Color(hex: hex)
                return tint < 0 ? color.mixed(with: .black, -tint) : color.mixed(with: Color(hex: 0x9A9870), tint)
            }
            sheets.append(Sheet(outline: points.map { Vector2((flipped ? 1 - $0.0 : $0.0) * w, $0.1 * h) },
                                base: toned(base), lit: toned(lit), lift: lift,
                                tucked: Vector2(0, from * h), free: Vector2(0, to * h), rim: rim,
                                entry: side, grainSeed: grainSeed, pale: pale))
        }

        // Which way the upper sheets read, and which side the lower slabs
        // come in from.
        let upper = coin(0.5), lower = coin(0.5), band = coin(0.5)

        // The measures the sheets hang on. The top sheet's edge sits near
        // half the golden cut and steps once or twice. The large sheet ends
        // on the golden cut, and steps up by the sixth cut toward one side.
        let topNear = pick([c[0] / 2, c[0] / 2 - 0.017, c[0] / 2 + 0.012]) + roll(-0.004 ... 0.004)
        let topStep = pick([c[2], 0.326, c[1], 0.472, 0.528])
        let topFar = topNear + (coin(0.7) ? -1 : 0.6) * pick([c[6], 0.045])
        let secondStep: Double? = coin(0.35) ? pick([c[0] + 0.056, c[0] + c[3]]) : nil
        let topEnd = topFar + (secondStep == nil ? 0 : (coin(0.5) ? c[6] : -c[6]))
        let sag = roll(0.004 ... 0.014)
        let strip = slabs >= 6
        let bodyNear = strip ? pick([c[4], c[4], 0.112]) : -over
        let bodyEdge = c[0] + roll(-0.003 ... 0.003)
        let bodyStep = pick([c[0], 0.674, 0.708, c[0] + c[3]])
        let raised = bodyEdge - c[5]
        let barb: Double? = coin(0.7) ? pick([c[2], 0.292, 0.326, c[1]]) : nil
        let tuck = min(topNear, topFar, topEnd) - 0.035

        // The deep panels, laid side by side under the large sheet. Some
        // touch, and some leave a slit or a wider gap of the black ground.
        let tones: [(UInt32, UInt32)] = [(0x53542F, 0x62633B), (0x4E401F, 0x625226), (0x4C4626, 0x5F572D),
                                         (0x44452A, 0x55563A)]
        var edge = -over
        let widths = [pick([c[2], 0.264, 0.292]), pick([0.19, 0.208, c[2]]), pick([0.2, c[2], 0.26]), 1.0]
        let firstTone = Int.random(in: 0 ..< tones.count, using: &rng)
        for (index, span) in widths.enumerated() where edge < 1 {
            let end = index == 0 ? span : min(1 + over, edge + span)
            let bottom = pick([0.81, 0.83, 0.853, 0.86, 0.853])
            let tone = tones[(firstTone + index) % tones.count]
            lay([(edge, raised - 0.07), (end, raised - 0.07), (end, bottom), (edge, bottom)], flipped: upper,
                base: tone.0, lit: tone.1, lift: 0.22, from: raised - 0.07, to: bottom)
            edge = end + pick([-0.004, -0.004, 0.012, c[5]])
        }
        let floorNear = pick([0.146, 0.2, 0.213, c[2]]), floorFar = pick([0.56, 0.612, 0.66])
        lay([(floorNear, 0.9), (floorFar, 0.893), (floorFar, 1 + over), (floorNear - 0.012, 1 + over)], flipped: lower,
            base: 0x4C4C25, lit: 0x615F2E, lift: 0.22, from: 0.9, to: 1.02)

        // The slab that carries most of the lower third, with a dark slab
        // standing behind it. One end is cut on a slant.
        let slabTop = pick([0.66, 0.674, 0.7]) + roll(-0.004 ... 0.004)
        let lead = pick([0.472, 0.528, 0.56, c[0]])
        let lean = coin(0.75) ? 0.055 : -0.04
        if slabs >= 2 {
            lay([(lead + 0.13, slabTop + 0.1), (1 + over, slabTop + 0.094), (1 + over, 0.862), (lead + 0.075, 0.862)],
                flipped: lower, base: 0x2E2F1B, lit: 0x45462A, lift: 0.25, entry: .fromRight,
                from: slabTop + 0.094, to: 0.862)
        }
        // The dark slab and the pale one under the raised part of the large
        // sheet.
        let far = bodyStep + 0.03
        if slabs >= 4 {
            lay([(far + 0.012, raised - 0.02), (1 + over, raised - 0.02), (1 + over, 0.705), (far + 0.004, 0.71)],
                flipped: upper, base: 0x35361F, lit: 0x4B4C2E, lift: 0.25, entry: .fromRight,
                from: raised, to: 0.71)
            lay([(far, raised - 0.03), (1 + over, raised - 0.03), (1 + over, raised + c[5] + 0.014),
                 (far - 0.006, raised + c[5] + 0.01)],
                flipped: upper, base: 0x565B3D, lit: 0x7A8160, lift: 0.6, rim: 0.5, entry: .fromRight, pale: true,
                from: raised - 0.01, to: raised + c[5] + 0.012)
        }
        // The tall strip beside the large sheet, with a hollow cut from its
        // outer side.
        if strip {
            let top = min(topNear, topFar) - 0.03
            let hollow = pick([0.165, 0.13, 0.2])
            var outline: [(Double, Double)] = [(0.038, top), (bodyNear + 0.035, top), (bodyNear + 0.02, bodyEdge - 0.006)]
            outline += [(-over, bodyEdge - 0.01), (-over, topNear + hollow + 0.007)]
            for step in 0 ... 5 {
                let angle = Double(5 - step) / 5 * .pi / 2
                outline.append((0.038 * cos(angle), topNear + hollow * sin(angle)))
            }
            lay(outline, flipped: upper, base: 0x687058, lit: 0x80876B, lift: 0.6, rim: 0.7, pale: true,
                from: top, to: bodyEdge)
        }
        // The pale strip that hangs down from under the large sheet and
        // turns along the bottom, on the side the slabs do not come from.
        if slabs >= 5 {
            let hang = pick([0.197, c[2], 0.264])
            lay([(hang, bodyEdge - 0.03), (hang + 0.053, bodyEdge - 0.03), (hang + 0.069, 0.924), (-over, 0.924),
                 (-over, 0.8), (hang + 0.026, 0.853)],
                flipped: lower, base: 0x626A52, lit: 0x7B8369, lift: 0.9, rim: 0.7, entry: .fromLeft, pale: true,
                from: bodyEdge, to: 0.924)
        }

        // The large sheet. Its upper corner on the far side is cut away, and
        // the black ground shows there as a long wedge under the top sheet.
        var body: [(Double, Double)] = [(bodyNear + 0.012, tuck), (pick([0.5, 0.62, 0.7]), tuck),
                                        (1 + over, topEnd + sag + roll(0.02 ... 0.045)),
                                        (1 + over, raised - 0.004), (bodyStep + 0.027, raised),
                                        (bodyStep, bodyEdge - 0.002)]
        if let barb {
            body += [(barb + 0.005, bodyEdge - 0.007), (barb + 0.022, bodyEdge + 0.013), (barb, bodyEdge + 0.005)]
        }
        body.append((bodyNear - 0.01, bodyEdge - 0.004))
        lay(body, flipped: upper, base: 0x504E2B, lit: 0x6C6639, lift: 1.0, from: topNear, to: bodyEdge)

        // The top sheet, across the whole width, with its steps.
        var top: [(Double, Double)] = [(-over, -over), (1 + over, -over), (1 + over, topEnd + sag)]
        if let secondStep {
            top += [(secondStep + 0.024, topEnd + sag * 0.6), (secondStep, topFar + sag * 0.5)]
        } else {
            top.append((0.8, topFar + sag * 0.55))
        }
        top += [(topStep + 0.026, topFar), (topStep, topNear - 0.004), (topStep * 0.5, topNear + 0.003),
                (-over, topNear + 0.006)]
        lay(top, flipped: upper, base: 0x4B4C2D, lit: 0x61633E, lift: 1.6, from: 0.02, to: max(topNear, topFar))

        // The pale slabs over the lower third, the long thin strip last.
        if slabs >= 2 {
            lay([(lead, slabTop + 0.004), (0.8, slabTop - 0.004), (1 + over, slabTop - 0.012), (1 + over, slabTop + 0.118),
                 (0.82, slabTop + 0.122), (0.735, slabTop + 0.134), (lead - lean, slabTop + 0.138)],
                flipped: lower, base: 0x636B55, lit: 0x7E866E, lift: 1.1, rim: 0.8, entry: .fromRight, pale: true,
                from: slabTop + 0.03, to: slabTop + 0.138)
        }
        if slabs >= 3 {
            let near = pick([0.528, 0.606, c[0], 0.652, 0.708])
            lay([(near, 0.883), (1 + over, 0.879), (1 + over, 1 + over), (near, 1 + over)],
                flipped: lower, base: 0x566351, lit: 0x6C7B70, lift: 0.6, rim: 0.5, entry: .fromRight, pale: true,
                from: 0.88, to: 1.02)
        }
        if slabs >= 1 {
            let near = pick([c[3], c[2], 0.264, 0.292, c[1]])
            lay([(near, c[0] + c[2] - 0.002), (1 + over, c[0] + c[2] - 0.011), (1 + over, c[0] + c[2] + c[6] - 0.009),
                 (near, c[0] + c[2] + c[6])],
                flipped: band, base: 0x5D6042, lit: 0x74795C, lift: 0.8, rim: 0.6, entry: .fromRight, pale: true,
                from: c[0] + c[2] - 0.01, to: c[0] + c[2] + c[6])
        }
        return sheets
    }

    // MARK: - The paint

    /// One sheet's paint. The color runs from the tucked side to the free
    /// edge and lightens a little toward every edge. It carries the clouding,
    /// the fine upright streaks, and the pits of the painted surface. The
    /// outline rides along as numbers, so the paint knows how far each pixel
    /// is from the nearest edge.
    private static let paint = """
    float4 shade(float2 uv, ShaderInfo info) {
        float3 base = float3(param(info, 0), param(info, 1), param(info, 2));
        float3 lit = float3(param(info, 3), param(info, 4), param(info, 5));
        float2 tucked = float2(param(info, 6), param(info, 7));
        float2 axis = float2(param(info, 8), param(info, 9));
        float seed = param(info, 10);
        float grain = param(info, 11);
        float rim = param(info, 12);
        float reach = param(info, 13);
        int count = int(param(info, 14));
        float2 p = info.position;
        float edge = 1.0e6;
        for (int i = 0; i < count; i++) {
            int j = (i + 1) % count;
            float2 a = float2(param(info, 15 + 2 * i), param(info, 16 + 2 * i));
            float2 b = float2(param(info, 15 + 2 * j), param(info, 16 + 2 * j));
            float2 ab = b - a;
            float along = clamp(dot(p - a, ab) / max(dot(ab, ab), 1.0e-6), 0.0, 1.0);
            edge = min(edge, length(p - a - ab * along));
        }
        float run = clamp(dot(p - tucked, axis), 0.0, 1.0);
        float lift = max(reach * run * run * (3.0 - 2.0 * run), rim * exp(-edge / 26.0));
        float3 color = mix(base, lit, lift);

        // Clouding at two sizes, a cool and a warm drift of the hue, fine
        // upright streaks, and pits that gather where the paint is darker.
        float cloud = fbm(p / 190.0 + seed * 7.31) - 0.5;
        float patch = fbm(p / 58.0 + seed * 2.17) - 0.5;
        float cool = smoothstep(0.48, 0.74, fbm(p / 240.0 + seed * 11.9));
        float warm = smoothstep(0.50, 0.78, fbm(p / 130.0 + seed * 4.63));
        float streak = valueNoise(float2(p.x / 1.7 + seed * 3.1, p.y / 46.0)) - 0.5;
        float fine = hash12(floor(p) + seed * 17.0) - 0.5;
        color *= 1.0 + grain * (0.42 * cloud + 0.30 * patch + 0.10 * streak + 0.10 * fine);
        color = mix(color, color * float3(0.86, 0.96, 1.0), 0.6 * grain * cool);
        color = mix(color, color * float3(1.12, 1.0, 0.78), 0.5 * grain * warm);
        float crowd = smoothstep(0.1, -0.25, cloud + patch);
        float pit = step(mix(0.9965, 0.972, crowd), hash12(floor(p / 1.6) + seed * 5.0));
        float fleck = step(0.9988, hash12(floor(p / 3.0) + seed * 9.0));
        color = mix(color, color * 0.5, grain * max(pit, fleck));
        return float4(color, 1.0);
    }
    """

    private func paint(for sheet: Sheet) -> Shader {
        // At the default `glow` the free edge is the color read off the
        // painting; more than that carries the same step further.
        let lit = sheet.base.mixed(with: sheet.lit, glow / 0.65)
        let span = sheet.free - sheet.tucked
        let axis = span / max(span.lengthSquared, 1)
        var numbers: [Float] = [Float(sheet.base.red), Float(sheet.base.green), Float(sheet.base.blue),
                                Float(lit.red), Float(lit.green), Float(lit.blue),
                                Float(sheet.tucked.x), Float(sheet.tucked.y), Float(axis.x), Float(axis.y),
                                Float(sheet.grainSeed), Float(grain), Float(sheet.rim * glow / 0.65),
                                Float(sheet.pale ? 0.35 : 1), Float(sheet.outline.count)]
        for point in sheet.outline {
            numbers += [Float(point.x), Float(point.y)]
        }
        return Shader(MansionDelAgua.paint, params: numbers, using: [.noise, .hash])
    }

    // MARK: - Drawing

    override func draw() {
        let seed = variation &+ pressed
        if built.seed != seed || built.slabs != slabs || built.width != width || built.height != height {
            built = (seed, slabs, width, height)
            composition = deal(seed: seed, slabs: slabs)
        }
        let cycle = max(8, seconds)
        let turn = (time / cycle).truncatingRemainder(dividingBy: 1)
        let angle = (light + swing * sin(2 * .pi * turn)) * .pi / 180
        // Light from the left throws its shadows to the right.
        let fall = Vector2(-sin(angle), cos(angle))
        let unit = 0.046 * height * depth

        background(ground)
        let laid = composition.indices.map { laidAmount(of: $0, among: composition.count, at: turn) }
        let bare = 1 - (laid.reduce(0, +) / Double(max(1, laid.count)))
        if bare > 0.001 {
            rule(alpha: 0.32 * bare)
        }
        for (index, sheet) in composition.enumerated() where laid[index] > 0 {
            lay(sheet, amount: laid[index], shadow: fall * (unit * sheet.lift))
        }
        if guides {
            rule(alpha: 0.6)
        }
    }

    /// How much of a sheet is on the canvas at `turn`, a part of the cycle
    /// from 0 to 1. The painting stands whole for the first 0.28 while the
    /// light drifts. Then the sheets come off, the nearest first, until
    /// 0.43, and the ground stands bare. From 0.46 they are laid again, the
    /// deepest first, and by 0.93 the last one is down. One sheet takes
    /// about two turns of the queue to go on, so the next begins before it
    /// has finished.
    private func laidAmount(of index: Int, among count: Int, at turn: Double) -> Double {
        let n = Double(count)
        func ease(_ x: Double) -> Double {
            let t = clamp(x, 0, 1)
            return t * t * (3 - 2 * t)
        }
        if turn < 0.28 { return 1 }
        if turn < 0.44 {
            let begun = 0.28 + 0.14 * Double(count - 1 - index) / n
            return 1 - ease((turn - begun) / (0.14 / n * 2.2))
        }
        let begun = 0.46 + 0.44 * Double(index) / n
        return ease((turn - begun) / (0.44 / n * 2.0))
    }

    /// Lay one sheet: its shadow on whatever is already there, then its
    /// paint, then the thin light line along its cut edge. A sheet that is
    /// partly laid is drawn inside the part of its box it has reached.
    private func lay(_ sheet: Sheet, amount: Double, shadow: Vector2) {
        let shape = Shape(sheet.outline, closed: true)
        let body = {
            self.noStroke()
            // The shadow is the sheet's own outline slid along the light's
            // fall, many times, each copy a thin coat of dark. Near copies
            // are heavier, so the dark is deepest at the edge and gone at
            // the shadow's full length.
            let length = shadow.length
            if length > 0.5 {
                let copies = max(6, min(28, Int(length / 2.5)))
                for k in 1 ... copies {
                    let part = (Double(k) - 0.5) / Double(copies)
                    let coat = 1 - exp(-0.95 * (0.75 + 0.5 * (1 - part)) / Double(copies))
                    self.fill(Color.black.withAlpha(coat))
                    self.withState {
                        self.translate(shadow * (Double(k) / Double(copies)))
                        self.drawShape(shape)
                    }
                }
                // The slit: the last few pixels under the edge, nearly black.
                let reach = min(length, 7.0)
                for k in 1 ... 4 {
                    self.fill(Color.black.withAlpha(0.3))
                    self.withState {
                        self.translate(shadow / length * (reach * Double(k) / 4))
                        self.drawShape(shape)
                    }
                }
            }
            self.fill(self.paint(for: sheet))
            self.drawShape(shape)
            self.noFill()
            self.stroke(sheet.lit.mixed(with: self.lip, sheet.pale ? 0.5 : 0.35).withAlpha(0.6))
            self.strokeWeight(1.3)
            self.drawShape(shape)
            self.noStroke()
        }
        if amount >= 1 {
            body()
            return
        }
        // The part of the canvas the sheet has reached so far.
        let xs = sheet.outline.map { clamp($0.x, 0, width) }, ys = sheet.outline.map { clamp($0.y, 0, height) }
        let left = xs.min() ?? 0, right = xs.max() ?? 0, top = ys.min() ?? 0, bottom = ys.max() ?? 0
        let reach = shadow.length + 4
        let far = 4 * max(width, height)
        let region: Rectangle
        switch sheet.entry {
        case .down:
            region = Rectangle(x: -far, y: -far, width: 2 * far, height: far + top + (bottom - top + reach) * amount)
        case .fromLeft:
            region = Rectangle(x: -far, y: -far, width: far + left + (right - left + reach) * amount, height: 2 * far)
        case .fromRight:
            let edge = right - (right - left + reach) * amount
            region = Rectangle(x: edge, y: -far, width: far, height: 2 * far)
        }
        withClip(region, body)
    }

    /// Rule the golden cuts across the canvas, both ways.
    private func rule(alpha: Double) {
        stroke(lip.withAlpha(alpha))
        strokeWeight(1)
        for cut in MansionDelAgua.lattice {
            drawLine(cut * width, 0, cut * width, height)
            drawLine(0, cut * height, width, cut * height)
        }
        noStroke()
    }
}

↑↓ move ↩ open