Ollin

LettresDeMaMere

Pages of a wordless handwriting, each line calm where it starts and restless where it ends, after Molnár's series of 1981 to 1990.

Run
swift run --package-path Examples Example-Recreations-VeraMolnar-LettresDeMaMere
Source
Examples/Recreations/VeraMolnar/LettresDeMaMere/Sketch.swift
//  Recreation after Vera Molnár - "Lettres de ma mère" (Letters from my
//  Mother), a series of 1981 to 1990: plotter drawings that look like pages
//  of handwriting and hold no words. The Musée de Grenoble holds ten of the
//  letters on one roll of paper four meters long (1988). The Victoria and
//  Albert Museum holds a screenprint of two of them as E.1079-2008 (1988).
//  A homage, not a reproduction, and not affiliated with or endorsed by the
//  artist's estate or the museums.
//  https://collections.vam.ac.uk/item/O216188/letters-from-my-mother-print-molnar-vera/
//  https://dam.org/museum/artists_ui/artists/molnar-vera/lettres-a-ma-mere/
//
//  An original Ollin interpretation. It was written from her own description
//  of the letters, which the Victoria and Albert Museum's record quotes, and
//  from pictures of the drawings. The counts were measured off the museum's
//  photograph of its print: 25 lines, about 86 strokes to a line, and the
//  first line set in by a ninth of its length. How the restlessness is made
//  here is this sketch's reading of those pictures, not a procedure she
//  published. Each stroke of the zigzag is made taller and longer by two
//  chance amounts. No code was read or ported.

import Foundation
import Ollin

/// "Lettres de ma mère" (Vera Molnár, 1981 to 1990). Her mother wrote to her
/// every week, in the hand taught to well-educated ladies of the Habsburg
/// monarchy. Molnár described that hand as part gothic and part hysteric.
/// Each line began "regular, severe, gothic" on the left and grew "more
/// nervous, restless, almost hysteric" toward its end. Over the years the
/// whole page went the same way, until the gothic was gone and only the
/// disorder was left. When the letters stopped coming, she went on writing
/// them to herself with a computer and a plotter.
///
/// A letter here is a block of lines, and a line is one zigzag. The pen
/// rises to the right, falls back more steeply, and does the same again
/// across the sheet. A rise and its fall make one stroke. That is the gothic
/// hand, and it has no words in it.
///
/// The restlessness is two chance amounts added to each stroke: how much
/// taller it stands, and how much farther it runs to the right. Each is
/// small most of the time and now and then large. So a restless line is even
/// strokes with a tall spike or a long flat one among them. How much can be
/// added depends on two things. One is how far along its line the stroke
/// stands. The other is how late in the years the letter was written. In an
/// early letter only the line ends stray. In a late one the calm start of
/// each line is a few strokes long. In the last there is none, and the
/// strokes are long steep slashes that cross four or five lines.
///
/// One lap writes `letters` letters, one after another, as a pen would:
/// line by line from the top, each line from left to right. Each letter is
/// later than the one before, and the last stands `years` of the way along.
/// A lap opens on that last letter, finished.
///
/// Try it: `years` at 0.4 with `letters` at 1 is close to the letter in the
/// museum's print. `lines` and `strokes` set how much writing a page holds,
/// and `lean` how far the calm strokes slope. `countered` turns the rule
/// around, restless where a line starts and calm where it ends, which is
/// the second letter of that print. A click rolls the next `seed`. The lines
/// export as strokes, so `--export-svg` gives a plotter drawing back.
@main
final class LettresDeMaMere: Sketch {

    /// How many letters one lap writes, each later in the years than the
    /// one before. The roll in Grenoble holds ten.
    @Param(1 ... 6, icon: "envelope") var letters = 3
    /// How far along the years the last letter of a lap stands. At 0 a
    /// letter is calm from end to end, and at 1 only the disorder is left.
    @Param(0 ... 1, icon: "hourglass") var years = 1.0
    /// Lines to a letter.
    @Param(8 ... 40, icon: "line.3.horizontal") var lines = 25
    /// Strokes in a full line. A stroke is one rise of the pen and the fall
    /// after it.
    @Param(30 ... 160, icon: "scribble") var strokes = 86
    /// How far the calm strokes lean to the right, in degrees from upright.
    @Param(0 ... 70, icon: "italic") var lean = 53.0
    /// The rule turned around: restless where a line starts, calm where it
    /// ends. The museum's print sets such a letter beside the plain one.
    @Param(icon: "arrow.left.arrow.right") var countered = false
    /// Seconds for one lap.
    @Param(8 ... 30, icon: "timer") var cycle = 30.0
    @Param(1 ... 9999, icon: "dice") var seed = 1988

    override var loopDuration: Double? { cycle }

    // MARK: The hand

    /// The first line starts this far in, as a share of a full line.
    static let indent = 0.11
    /// A calm stroke's height, as a share of the space between two lines.
    static let strokeHeight = 0.48
    /// How much of a line the restlessness takes to come up to full, as a
    /// share of the line.
    static let rise = 0.6
    /// The share of the restlessness every stroke of a letter carries, even
    /// at the calm end of its line: the odd tall stroke among even ones.
    static let everywhere = 0.15
    /// The most a stroke's top can rise above a calm one, in calm stroke
    /// heights, and the most it can run on to the right, in calm runs. The
    /// first is much the larger, so the long strokes of the last letters
    /// stand steep.
    static let highest = 9.0, widest = 1.8
    /// How much faster a stroke's run to the right grows than its height.
    /// A stroke of the middle years is long and flat more often than tall.
    static let sideways = 1.5
    /// How far a stroke's foot strays, down and to the left, as a share of
    /// how far its top strays up and to the right.
    static let footing = 0.7

    /// How restless a stroke is: 0 is the calm hand, and at 1 a stroke
    /// stands about twice as tall as a calm one. `place` runs 0 to 1 along
    /// the line in the direction the restlessness grows, and `age` runs 0 to
    /// 1 through the years.
    ///
    /// Two things move with the years. The place where a line stops being
    /// calm travels back toward its start, reaching it at four fifths of
    /// the way through. And the most a stroke can stray grows, slowly at
    /// first and fast at the end.
    static func restlessness(at place: Double, age: Double) -> Double {
        guard age > 0 else { return 0 }
        let most = age * (1.2 + 11 * pow(age, 2.2))
        let calmUntil = 1 - 1.25 * age
        let up = min(1, max(0, (place - calmUntil) / rise))
        return most * (everywhere + (1 - everywhere) * pow(up, 1.3))
    }

    /// An amount bent so that it never passes `limit`. A small amount stays
    /// as it is. A large one comes up to the limit and stops short of it.
    static func bent(_ amount: Double, limit: Double) -> Double {
        limit * (1 - exp(-amount / limit))
    }

    /// One letter as the pen's path: a list of lines, top line first, each
    /// a zigzag of points in sheet units (the block is 1 wide, a line apart
    /// is `pitch`). Every stroke takes four rolls of the seed whether it
    /// strays or not, so the same seed at another age is the same letter,
    /// grown older.
    static func letter(age: Double, lines: Int, strokes: Int, lean: Double, pitch: Double,
                       countered: Bool, seed: UInt64) -> [[Vector2]] {
        var generator = SplitMix64(seed: seed)
        func roll() -> Double { Double(generator.next() >> 11) * 0x1p-53 }
        /// A chance amount that is small most of the time and now and then
        /// large: one on average, under 0.7 half of the time, and past
        /// three once in twenty.
        func stray() -> Double { -log(1 - roll()) }

        let step = 1 / Double(max(1, strokes))
        let height = strokeHeight * pitch
        let reach = height * tan(lean * .pi / 180)

        var page: [[Vector2]] = []
        for line in 0 ..< lines {
            let first = line == 0 ? Int((indent * Double(strokes)).rounded()) : 0
            let baseline = Double(line) * pitch
            var path: [Vector2] = []
            for stroke in first ... strokes {
                let x = Double(stroke) * step
                let restless = restlessness(at: countered ? 1 - x : x, age: age)
                // The foot of the stroke, which strays down and to the left
                // of its place on the line. Then its top, which strays up
                // and to the right.
                let back = bent(restless * sideways * stray(), limit: widest)
                let below = bent(restless * stray(), limit: highest)
                let along = bent(restless * sideways * stray(), limit: widest)
                let above = bent(restless * stray(), limit: highest)
                path.append(Vector2(x - reach * footing * back, baseline + height * footing * below))
                guard stroke < strokes else { break }
                path.append(Vector2(x + reach * (1 + along), baseline - height * (1 + above)))
            }
            page.append(path)
        }
        return page
    }

    // MARK: The lap

    /// Where the lap is: which letter is on the sheet, how much of it the
    /// pen has written, and how much ink the sheet carries. A lap is one
    /// turn for each letter. A turn opens on the letter before, finished,
    /// lets it go back to paper, and writes its own.
    static func stage(at lap: Double, letters count: Int) -> (letter: Int, written: Double, ink: Double) {
        let hold = 0.28, clear = 0.36
        let place = lap * Double(count)
        let turn = min(count - 1, Int(place))
        let within = place - Double(turn)
        let before = (turn + count - 1) % count
        if within < hold { return (before, 1, 1) }
        if within < clear {
            let gone = (within - hold) / (clear - hold)
            return (before, 1, 1 - gone * gone * (3 - 2 * gone))
        }
        return (turn, (within - clear) / (1 - clear), 1)
    }

    let paper = Color(hex: 0xF5F1EA)
    let ink = Color(hex: 0x3565A8)

    /// A click rolls the next letters.
    override func mousePressed() {
        seed = seed >= 9999 ? 1 : seed + 1
    }

    override func draw() {
        background(paper)
        let stage = Self.stage(at: loopProgress(over: cycle), letters: letters)
        let age = years * Double(stage.letter + 1) / Double(letters)

        // The block of writing: about three quarters of the sheet wide, and
        // lines spaced so that 25 of them fill three fifths of its height.
        let side = min(width, height)
        let across = side * 0.74
        let pitch = side * 0.6 / Double(max(1, lines - 1))
        let corner = Vector2(center.x - across / 2,
                             center.y - pitch * Double(lines - 1) / 2 + pitch * Self.strokeHeight / 2)

        let page = Self.letter(age: age, lines: lines, strokes: strokes, lean: lean,
                               pitch: pitch / across, countered: countered,
                               seed: UInt64(seed) &* 0x9E37_79B9_7F4A_7C15 &+ UInt64(stage.letter))
            .map { line in line.map { corner + $0 * across } }

        // The pen keeps one pace, so a line takes its share of the letter's
        // whole length.
        let lengths = page.map { Contour($0, closed: false).length }
        var left = stage.written >= 1 ? Double.infinity : stage.written * lengths.reduce(0, +)

        noFill()
        stroke(ink)
        strokeWeight(side * 0.001)
        strokeCap(.round)
        strokeJoin(.round)
        for (line, length) in zip(page, lengths) {
            guard left > 0 else { break }
            // The line the pen is on is drawn as far as the pen has come.
            drawPolyline(left >= length
                ? line : Contour(line, closed: false).piece(from: 0, to: left / length).points)
            left -= length
        }

        // A finished letter goes back to paper before the next is written.
        // A vector export keeps the strokes alone.
        if stage.ink < 1, !isVectorExporting {
            noStroke()
            fill(paper.withAlpha(1 - stage.ink))
            drawRect(0, 0, width, height)
        }
    }
}

↑↓ move ↩ open