Ollin

Tecelar

A black block with thirty-one white lines cut into it, eighteen of them turning a right angle, after Lygia Pape's Tecelar (1957).

Run
swift run --package-path Examples Example-Recreations-LygiaPape-Tecelar
Source
Examples/Recreations/LygiaPape/Tecelar/Sketch.swift
//  Recreation after Lygia Pape - a Tecelar (Weaving) of 1957, a woodcut on
//  Japanese paper from a block about 50 centimeters square. The impression
//  read here belongs to the Projeto Lygia Pape and was shown at K20 in
//  Düsseldorf in 2022. The Museu de Arte Moderna de São Paulo holds an
//  impression of the same block, hung a quarter turn clockwise. A homage,
//  not a reproduction, and not affiliated with or endorsed by the artist's
//  estate or the museums.
//  https://kunstsammlung.de/en/press/lygia-pape-the-skin-of-all-en
//  https://artsandculture.google.com/asset/untitled-series-tecelares/dgGiltEY1_aM-g
//  https://www.moma.org/collection/works/63188
//
//  An original Ollin interpretation, written from pictures of the two
//  impressions and from published accounts of how she cut and printed. The
//  counts and proportions are measured off the press picture of the estate's
//  impression. No published account gives them, and none says in what order
//  she cut the lines, so the order here is a guess. Nothing was ported: the
//  block was cut by hand and printed without a press.

import Foundation
import Ollin

/// A *Tecelar* (Lygia Pape, Rio de Janeiro, 1957): a black square with white
/// lines cut into it. **Press** to deal another block.
///
/// She inked a plank of wood and printed it by hand on thin Japanese paper.
/// Wherever the tool had cut a narrow trough, no ink reached the paper, so
/// each cut prints as a white line. The plank's own grain prints too, as
/// small pale flecks that run one way through the black.
///
/// This block holds `lines` cuts, one pitch apart, all standing on a solid
/// band `band` pitches high. The first of them run straight up to the top
/// edge. The last `corners` of them stop short and turn right, each one a
/// pitch lower than the one before, and run out to the right edge. So half
/// of the square is plain stripes and half is a fan of nested right angles.
/// Nothing is drawn but parallel lines, and the flat black seems to fold.
///
/// She cut by hand, so no line is quite on its mark and each is a little
/// ragged. Where the tool left the wood, at the band, a cut ends in a point.
/// `hand` is how much of that shows, and at 0 every cut is exact. `grain` is
/// how much the wood shows through the ink.
///
/// She said these prints have no privileged base or bottom, and she hung
/// impressions of one block different ways up. `turns` hangs the sheet
/// a quarter turn clockwise at a time. One turn is how the impression in São
/// Paulo hangs. `block` set to `portals` is a sister block, which she dated
/// both 1956 and 1959: every line turns twice and comes down the other side,
/// so the cuts are doorways one inside the next. With `lines` at 24 it has
/// that block's twelve.
///
/// A lap opens on the finished print. Then the sheet clears to a fresh block
/// and the cuts are made again, one at a time at a steady pace.
///
/// Try it: `--export-svg` gives the block as a cutting plan, its outline and
/// one stroke for every cut. With `hand` at 0 the strokes are exactly on the
/// rule.
@main
final class Tecelar: Sketch {
    enum Block: String, CaseIterable, ParamOption {
        /// 1957: plain stripes, a fan of nested corners, and a solid band.
        case corners
        /// The block dated 1956 and 1959: doorways one inside the next.
        case portals
    }

    /// Which block is cut.
    @Param(icon: "square.on.square") var block = Block.corners
    /// The lines cut into the block.
    @Param(12 ... 44, icon: "line.3.horizontal") var lines = 31
    /// How many of them turn a right angle, counted from the right.
    @Param(0 ... 30, icon: "arrow.turn.down.left") var corners = 18
    /// The height of the solid band the lines stand on, in pitches.
    @Param(0 ... 10, icon: "rectangle.bottomthird.inset.filled") var band = 5.0
    /// Quarter turns clockwise the sheet is hung at.
    @Param(0 ... 3, icon: "rotate.right") var turns = 0
    /// How much of the hand shows: lines off their marks, ragged, and pointed
    /// where the tool left the wood. At 0 every cut is exact.
    @Param(0 ... 1, icon: "hand.draw") var hand = 1.0
    /// How much the plank's grain shows through the ink.
    @Param(0 ... 1, icon: "tree") var grain = 0.5
    /// Seconds for one lap: the finished print, a fresh block, and the cutting.
    @Param(12 ... 30, icon: "timer") var seconds = 24.0

    override var canvasSize: CanvasSize { .square(1080) }
    override var loopDuration: Double? { seconds }

    private let paper = Color(hex: 0xD3CBBF)
    private let ink = Color(hex: 0x0D0C0C)
    /// The side of the block on the canvas.
    private let side = 920.0

    /// One cut: the path the tool takes through the block, in canvas points
    /// from the block's top left corner.
    struct Cut {
        /// The corners of the path, exactly on the rule or off it by the hand.
        var marks: [Vector2]
        /// The same path as it is drawn, with the hand's small waver in it.
        var path: [Vector2]
        /// How far along the path each of its points is.
        var along: [Double]
        /// Whether the tool leaves the wood at the end, which makes a point.
        var endsInWood: Bool
        /// How wide the trough is at each third of a pitch along the path,
        /// as a share of its plain width. A hand does not hold one width.
        var widths: [Double]

        var length: Double { along.last ?? 0 }
    }

    private var cuts: [Cut] = []
    private var pitch = 1.0
    /// The block sits a little askew on its sheet, as a hand lays it.
    private var askew = 0.0
    private var flecks: Batch?
    private var built = ""
    private var dealt = 0

    override func mousePressed() {
        dealt += 1
    }

    // MARK: - The frame

    override func draw() {
        let key = "\(variation)/\(dealt)/\(block)/\(lines)/\(corners)/\(band)/\(hand)/\(grain)"
        if key != built {
            cutTheBlock(seed: variation &+ dealt &* 7919)
            built = key
        }

        let (done, shown) = stage(at: loopProgress(over: seconds))

        if isVectorExporting {
            drawThePlan(done: done)
            return
        }

        background(paper)
        translate(width / 2, height / 2)
        rotate(Double(turns) * .pi / 2 + askew)
        translate(-side / 2, -side / 2)

        noStroke()
        fill(ink)
        drawRect(0, 0, side, side)
        if let flecks { drawBatch(flecks) }
        drawTheCuts(done: done, shown: shown)
    }

    /// Where the lap is: how much of the cutting is done (0 to 1) and how
    /// much the cuts show. The lap opens on the finished print, clears to a
    /// fresh block, and cuts it again.
    private func stage(at lap: Double) -> (done: Double, shown: Double) {
        let hold = 0.12, clear = 0.2, finished = 0.95
        if lap < hold { return (1, 1) }
        if lap < clear {
            let gone = (lap - hold) / (clear - hold)
            return (1, 1 - smoothstep(0, 1, gone))
        }
        return (min(1, (lap - clear) / (finished - clear)), 1)
    }

    // MARK: - Cutting the block

    /// Lays out every cut and records the grain. Everything comes from the
    /// seed, so a seed is a block.
    private func cutTheBlock(seed: Int) {
        var rng = SplitMix64(seed: UInt64(bitPattern: Int64(seed &* 1_000_003 &+ 1957)))
        func roll() -> Double { Double(rng.next() >> 11) / Double(1 << 53) }
        /// How far a cut lands from its mark, in pitches. Her gaps differ
        /// from one another by a few parts in a hundred.
        func slip() -> Double { (roll() - 0.5) * 0.07 * hand }

        noiseSeed(seed)
        askew = (roll() - 0.5) * 0.012 * hand
        var marks: [(points: [Vector2], endsInWood: Bool)] = []

        switch block {
        case .corners:
            // The side is the lines, a narrow margin on the left, and a
            // whole pitch on the right.
            let count = max(2, lines)
            pitch = side / (Double(count) + 0.3)
            let foot = side - band * pitch
            // A line turns only while its corner stands clear of the band.
            let room = Int(((foot / pitch) - 0.45).rounded(.down))
            let turning = max(0, min(corners, count, room))
            let straight = count - turning
            for i in 0 ..< count {
                let x = (0.3 + Double(i) + slip()) * pitch
                if i < straight {
                    marks.append(([Vector2(x, 0), Vector2(x, foot)], band > 0))
                } else {
                    // Each corner a pitch lower and a pitch farther right
                    // than the last. The tool comes in from the right edge.
                    let k = Double(i - straight + 1)
                    let y = (k - 0.55 + slip()) * pitch
                    marks.append(([Vector2(side, y), Vector2(x, y), Vector2(x, foot)], band > 0))
                }
            }
        case .portals:
            // Doorways on the middle axis, the smallest two pitches wide
            // with its top at the middle of the block.
            let count = max(1, lines / 2)
            pitch = side / (Double(count * 2) + 1)
            let middle = side / 2
            for k in 1 ... count {
                let left = middle - (Double(k) + slip()) * pitch
                let right = middle + (Double(k) + slip()) * pitch
                let top = middle - (Double(k - 1) + slip()) * pitch
                marks.append(([Vector2(left, side), Vector2(left, top),
                               Vector2(right, top), Vector2(right, side)], false))
            }
        }

        cuts = marks.map { mark in
            let phase = roll() * 400
            let path = waver(mark.points, phase: phase)
            var along = [0.0]
            for i in 1 ..< path.count {
                along.append(along[i - 1] + (path[i] - path[i - 1]).length)
            }
            let stations = Int((along[along.count - 1] / (pitch / 3)).rounded(.up)) + 2
            var widths: [Double] = []
            for station in 0 ..< stations {
                let ragged: Double = signedNoise(Double(station) * 0.48, phase + 7)
                widths.append(1 + 0.2 * hand * ragged)
            }
            return Cut(marks: mark.points, path: path, along: along,
                       endsInWood: mark.endsInWood, widths: widths)
        }
        flecks = grain > 0 ? printTheGrain(seed: seed) : nil
    }

    /// A path with the hand's waver in it: points every half pitch, each
    /// pushed a little to one side. The waver dies away toward each corner,
    /// so the corners stay where they were marked.
    private func waver(_ points: [Vector2], phase: Double) -> [Vector2] {
        guard hand > 0 else { return points }
        var path: [Vector2] = [points[0]]
        var traveled = 0.0
        for i in 1 ..< points.count {
            let a = points[i - 1], b = points[i]
            let span = (b - a).length
            guard span > 0 else { continue }
            let forward = (b - a) / span
            let across = Vector2(-forward.y, forward.x)
            let steps = max(1, Int((span / (pitch * 0.5)).rounded()))
            for s in 1 ... steps {
                let f = Double(s) / Double(steps)
                let settle = min(1, min(f, 1 - f) * span / pitch)
                let push = signedNoise((traveled + f * span) / (pitch * 2.6), phase)
                path.append(a + forward * (f * span) + across * (push * 0.014 * hand * pitch * settle))
            }
            traveled += span
        }
        return path
    }

    /// The plank's grain, recorded once. The grain lines come from
    /// `WoodGrain`, running up the block, and only short stretches of each
    /// are kept: the pores that took no ink. They gather in streaks, as
    /// they do across a real plank.
    private func printTheGrain(seed: Int) -> Batch {
        var rng = SplitMix64(seed: UInt64(bitPattern: Int64(seed &* 7_368_787 &+ 11)))
        func roll() -> Double { Double(rng.next() >> 11) / Double(1 << 53) }

        let lean = (roll() - 0.5) * 0.2
        let wood = WoodGrain.trace(in: Rectangle(corner: .zero, width: side, height: side),
                                   direction: .pi / 2 + lean, spacing: pitch * 0.085, knots: 0,
                                   ringSpacing: pitch * 2.2, ringContrast: 0.3, wobble: 0.3, seed: seed)
        struct Fleck { var points: [Vector2]; var weight: Double; var alpha: Double }
        var kept: [Fleck] = []
        for stroke in wood.strokes {
            let points = stroke.points
            guard points.count > 1 else { continue }
            var i = 0
            while i < points.count - 1 {
                let p = points[i]
                // Streaks: the pores change quickly across the grain and
                // slowly along it.
                let streak = noise(p.x / (pitch * 0.55), p.y / (pitch * 11) + 40)
                let patch = noise(p.x / (pitch * 6) + 90, p.y / (pitch * 7))
                let open = pow(streak, 3.2) * (0.1 + 2.2 * pow(patch, 2.2)) * grain
                if roll() < min(0.2, open * 0.3) {
                    // A pore: a short run of the grain line, longer where
                    // the wood is more open.
                    let reach = pitch * (0.06 + 0.7 * roll() * roll())
                    var run = [p]
                    var covered = 0.0
                    var j = i
                    while j < points.count - 1, covered < reach {
                        covered += (points[j + 1] - points[j]).length
                        run.append(points[j + 1])
                        j += 1
                    }
                    kept.append(Fleck(points: run, weight: pitch * (0.008 + 0.016 * roll()),
                                      alpha: 0.25 + 0.45 * roll()))
                    i = j + 1
                } else {
                    i += 1
                }
            }
        }
        return makeBatch {
            noFill()
            strokeCap(.butt)
            for fleck in kept {
                stroke(paper.withAlpha(fleck.alpha))
                strokeWeight(fleck.weight)
                drawPolyline(fleck.points)
            }
        }
    }

    // MARK: - Drawing the cuts

    /// The part of each cut made so far. The tool keeps one pace, so the
    /// share of the lap a cut takes is its share of all the length.
    private func madeSoFar(done: Double) -> [(cut: Cut, reach: Double)] {
        if done >= 1 { return cuts.map { ($0, $0.length) } }
        let whole = cuts.reduce(0) { $0 + $1.length }
        var left = done * whole
        var made: [(Cut, Double)] = []
        for cut in cuts {
            if left <= 0 { break }
            made.append((cut, min(cut.length, left)))
            left -= cut.length
        }
        return made
    }

    /// The points of a path up to a distance along it.
    private func prefix(_ cut: Cut, to reach: Double) -> [Vector2] {
        if reach >= cut.length { return cut.path }
        var points: [Vector2] = [cut.path[0]]
        for i in 1 ..< cut.path.count {
            if cut.along[i] <= reach {
                points.append(cut.path[i])
            } else {
                let span = cut.along[i] - cut.along[i - 1]
                let f = span > 0 ? (reach - cut.along[i - 1]) / span : 0
                points.append(cut.path[i - 1] + (cut.path[i] - cut.path[i - 1]) * f)
                break
            }
        }
        return points
    }

    private func drawTheCuts(done: Double, shown: Double) {
        guard shown > 0 else { return }
        noFill()
        stroke(paper.withAlpha(shown))
        strokeCap(.butt)
        strokeJoin(.miter)
        strokeWeight(pitch * 0.088)
        for (cut, reach) in madeSoFar(done: done) {
            let points = prefix(cut, to: reach)
            guard points.count > 1 else { continue }
            if hand > 0 {
                let whole = cut.length, widths = cut.widths
                let tail = cut.endsInWood ? pitch * 0.42 : 0
                let nose = reach < whole ? pitch * 0.35 : 0
                let station = pitch / 3
                strokeProfile { t in
                    let at = t * reach
                    let place = min(at / station, Double(widths.count - 1))
                    let low = min(Int(place), widths.count - 2)
                    var width = widths[low] + (widths[low + 1] - widths[low]) * (place - Double(low))
                    // The point where the tool left the wood.
                    if tail > 0, at > whole - tail { width *= pow(max(0, (whole - at) / tail), 0.8) }
                    // The tool's own point, while it is still cutting.
                    if nose > 0, at > reach - nose { width *= max(0, (reach - at) / nose) }
                    return width
                }
            }
            drawPolyline(points)
        }
        noStrokeProfile()
    }

    /// The block as a cutting plan: its outline and one plain stroke for
    /// every cut, through the marks the hand made.
    private func drawThePlan(done: Double) {
        background(.white)
        translate(width / 2, height / 2)
        rotate(Double(turns) * .pi / 2 + askew)
        translate(-side / 2, -side / 2)
        noFill()
        stroke(.black)
        strokeJoin(.miter)
        strokeWeight(1)
        drawRect(0, 0, side, side)
        for (cut, reach) in madeSoFar(done: done) where reach >= cut.length {
            drawPolyline(cut.marks)
        }
    }
}

↑↓ move ↩ open