Skip to content

Latest commit

 

History

History
489 lines (358 loc) · 31 KB

fields.mdx

File metadata and controls

489 lines (358 loc) · 31 KB
title Fields
description Functions of position that shapes, fills and materials read.

A field is a function of position. A scalar field is (x, y) => number. A vector field is (x, y) => [dx, dy]. A field receives drawable units. Fills, modifiers, scatter, isolines and streamlines read them, so one function can decide tone, spacing and direction in the same drawing. Every word that samples a field on a lattice takes step, the lattice pitch as a length.

t.isolines()

/_sig/Toolkit.isolines.mdx

The level lines of a field, as one material. Give one value, a list of them, or a count or a spacing. Every edge carries its level, and every edge of the material is a level line with cut = 0. The lines are what t.isolines calculates. The area of a level is where the field is at the value or above it. When polygon, contours() or t.within asks for the area, the library calculates the area one time and keeps it. Each area is a ring. It closes along the drawable, along a t.within bound and around each hole in the field. It goes through each corner that is in the area. The edges that close a ring carry cut = 1.

polygon(m) fills the areas with their holes. strokes(m) draws the level lines. m.points and m.edges count the level lines only. The closing edges belong to the area: m.faces has them, and polygon uses them. A selection of the lines is an area too. polygon(sel) closes it with each closing run that joins two ends of the selection. m.edges.groupBy((e) => e.level) splits the levels (see Selections). step is the pitch of the sample grid. The default is the larger of 1 mm and the long side divided by 256. For a field with a t.within bound, the grid covers only the box of the bound. A fine step on a small bound is not expensive. There is no close option, because each area closes. The call refuses close by name, and it refuses a key that is not part of a level spec by name.

import { sketch, strokes } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 2 }, (t) => {
  const ground = (x, y) => t.noise(x / 28, y / 28);
  const lines = t.isolines(ground, [-0.4, -0.2, 0, 0.2, 0.4]).edges;
  return lines.groupBy((e) => e.level).map((sel) => strokes(sel, { pen: sel.key > 0 ? 'stabilo-88-blue' : undefined }));
});

A high ground that runs off the sheet is still an area. Here the hatch fills each part of it to the edge of the drawable, and the pen draws only the level line.

import { sketch, strokes, polygon, fill, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 4 }, (t) => {
  const ground = (x, y) => t.noise(x / 30, y / 30);
  const high = t.isolines(ground, 0.15);
  return [
    polygon(high, { stroke: false, fill: fill('hatch', { angle: 30, spacing: mm(1) }) }),
    strokes(high),
  ];
});

A coarse grid shows in the contours of a field with fine detail. Here the drawing shows the Mandelbrot count twice. Left of c = 0 the contours use the default step, and right of it they use step: mm(0.25). The stairs at the edge of the set are the grid, and on the right they go.

import { sketch, strokes, escape, complex, rect, pen, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 21, pens: {
  fine: pen({ width: mm(0.3), color: '#23252B' }),
} }, (t) => {
  const b = t.bounds();
  const field = escape((z, c) => complex.add(complex.mul(z, z), c), { input: 'c', iterations: 60, bailout: 1e6 });
  // The sheet as the c-plane, as in the escape() example: x = 64 is c = 0.
  const count = (x, y) => field((x - 64) / 34, (y - 50) / 34);
  // The same contours at two grid pitches, each kept on its own side of c = 0.
  const side = (area, step) => strokes(t.within(t.isolines(count, { spacing: 2 }, { step }), area), { pen: 'fine' });
  return [side(rect(0, 0, 64, b.h), undefined), side(rect(64, 0, b.w - 64, b.h), mm(0.25))];
});

Levels

at takes one value, a list of values, { count } or { spacing }. It is the spelling the 3D isolines takes, and both read it the same way. A count spreads that many levels evenly inside the range the field covers. A spacing takes every multiple of one step inside that range. min and max pin the range for a count. offset shifts the multiples for a spacing. The range comes from the same samples the contours come from. A count of 0, a spacing of 0 and a flat field all draw nothing.

A map marks every fifth contour. Two calls make one. The first takes the base spacing. The second takes five times the spacing in a second pen. A different pen always draws, so the order of the two calls is free.

import { sketch, strokes } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 11 }, (t) => {
  const ground = (x, y) => t.noise(x / 46, y / 46) + t.noise(x / 17, y / 17) * 0.3 - (y - 50) / 220;
  return [strokes(t.isolines(ground, { spacing: 0.08 }), { pen: 'pigma-005-black' }), strokes(t.isolines(ground, { spacing: 0.4 }), { pen: 'stabilo-88-blue' })];
});

t.distanceTo()

/_sig/Toolkit.distanceTo.mdx

A signed distance field from a boundary: positive inside, zero on it, negative outside. A field from the library also takes one point: d(p) is d(p[0], p[1]), for a pair or an { x, y } object. This is true for t.distanceTo, t.travelTime, t.within and the field transforms. The sdf words and the pure distanceTo take (x, y) only. t.isolines(d, 2) is a ring 2 units inside the boundary, and t.isolines(d, -2) a halo 2 units outside. There is no separate offset function. The boundary is a shape, loops, a list of contours, a face, or a chain material. t.distanceTo reads the boundary's contours(). An open shape has no inside. So t.distanceTo(line(a, b)) is the signed distance to the line through a and b, positive on its left. This is true in a flat sketch and in a curved one.

t.distanceTo measures in the space of the geometry. When the geometry has no space, as loops, points and a shape have not, it measures in the space of the sketch. The pure import distanceTo measures in the space its argument carries: a material or a selection made in a curved sketch. Plain loops, points and a list of contours carry none, so it measures those flat.

import { sketch, strokes, ngon } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const d = t.distanceTo(t.material(ngon(50, 50, 5, 34)));
  return strokes(t.isolines(d, [-6, -3, 0, 3, 6, 9, 12]));
});

Points have no inside. A point selection or a material of points alone is points. Of points, t.distanceTo is the distance to the nearest point, with the same sign. The value is zero at a point and negative everywhere else, so no part of the field lies inside. t.isolines(d, -3) is the ring three units out from every site. Two rings that reach each other join, and the join runs along the wall between those two sites. A t.scatter result or a material's points goes straight in. A plain array of pairs is a loop, so material(pairs) makes it points. The field reads no seed.

Dried mud. Close levels near the merge depth make plates, and the gaps left between the plates are the cracks.

import { sketch, strokes } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 11 }, (t) => {
  const sites = t.relax(t.scatter({ spacing: 11 }), { iterations: 2 });
  const d = t.distanceTo(sites);
  return [
    strokes(t.isolines(d, [-6.9]), { pen: 'pigma-05-black' }),
    strokes(t.isolines(d, [-6.4, -5.6]), { pen: 'pigma-005-black' }),
  ];
});

sdf.circle() · sdf.box() · sdf.segment()

/_sig/sdf.circle.mdx /_sig/sdf.box.mdx /_sig/sdf.segment.mdx

A shape can be the field that measures it. These three are exact. They spell their arguments as circle and line do: sdf.circle(p, r), sdf.box(p, w, h) and sdf.segment(a, b, r) take each point as one value. They carry the same sign as t.distanceTo: how far inside the point lies, and negative outside. t.isolines(f, 0) draws the boundary back out.

import { sketch, strokes, sdf } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const bar = sdf.segment(24, 72, 76, 28, 10);
  return strokes(t.isolines(bar, [-28, -22, -16, -10, -5, 0, 5, 9]));
});

sdf.union() · sdf.intersect() · sdf.subtract()

/_sig/sdf.union.mdx /_sig/sdf.intersect.mdx /_sig/sdf.subtract.mdx

These combine shapes. union is a maximum, because inside is the positive side and the union is inside wherever either field is inside. intersect is the minimum, and subtract cuts every later field out of the first. Each answer is a field again, and feeds the next operation. Below, a disc and a box join. Two smaller discs cut holes in them. A larger disc then crops the result. The part that survives is inside both.

Each of the three takes one array of fields, or the fields themselves. A list you computed goes straight in. sdf.union(discs) is sdf.union(...discs), and sdf.subtract(plate, holes) cuts every hole in the array. A mix of the two spellings is a mistake, and the library refuses it by name.

import { sketch, polygon, strokes, sdf, fill, mm } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const body = sdf.union(sdf.circle(38, 38, 28), sdf.box(62, 66, 52, 30));
  const holes = sdf.union(sdf.circle(36, 36, 11), sdf.circle(72, 66, 8));
  const plate = sdf.intersect(sdf.subtract(body, holes), sdf.circle(50, 50, 42));
  return [
    polygon(t.isolines(plate, 0), { fill: fill('hatch', { angle: 40, spacing: mm(1.4) }) }),
    strokes(t.isolines(plate, -5)),
  ];
});

sdf.blend()

/_sig/sdf.blend.mdx

blend is a union with a fillet of radius where the two shapes meet. Two discs that only come close become one body, and the join is a curve neither shape describes. Away from the joint it is exactly the union. Within radius of the joint the corner becomes an arc, so the shape is a little larger there.

A whole list blends at one radius. sdf.blend(parts, radius) blends the first two fields, then that body with the third, and so on. An empty list is nowhere, and one field is itself. The radius stays last, so the list form is not variadic. sdf.blend(a, b, c, r) would make the meaning depend on the number of arguments.

import { sketch, polygon, sdf, fill, mm, ui } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 3 }, (t) => {
  const r = ui(9, { min: 0, max: 18 });
  const parts = t.grid({ cols: 3, rows: 3 }).faces.map((f) => sdf.circle(f.bounds.cx, f.bounds.cy, 15.5));
  const body = sdf.blend(parts, r);
  return polygon(t.isolines(body, 0), { fill: fill('hatch', { angle: 20, spacing: mm(1.3) }) });
});

:::note A box is always centred, and that is why it is not called rect. rect(x, y, w, h) anchors by the sketch's own rect mode, and a pure field function cannot read the sketch. One name with two anchors is a trap. The algebra takes plain numbers for the same reason. A length in the sketch's units needs the resolved paper, so resolve it first with t.bounds(). :::

:::warning The algebra reads its fields as distances. sdf.union of two noise fields is the larger noise, and that means nothing. Combine only fields that measure a shape: these three, t.distanceTo, and what the algebra itself returns. :::

:::note A boundary stays exact, and the depth behind it does not. union measures correctly outside the shape and understates depth inside, because the nearest boundary may belong to the other field. intersect is the reverse. Contour at zero and the outline is right. Read a level far from zero near a seam and it is an estimate. :::

t.travelTime()

/_sig/Toolkit.travelTime.mdx

The time a front needs to reach each point of the drawable. The front starts at its source at time zero, and the options name the source. Under fromPoints every entry is a separate seed, a pair or an { x, y } object. Under fromArea the input is one area or a shape. Give one key or the other, and the call refuses both keys at once by name. speed is a number or a field, and 1 is the default. A speed of zero or less is a wall, and the front walks around it. within names the ground, and the drawable is the default. Unreachable ground reads +Infinity, so contours stop at a barrier. On open ground at speed 1 the answer is the straight-line distance: the value of t.distanceTo without its sign. t.distanceTo is negative outside an area. The travel time is not. step is the pitch of the grid that the front moves on. Its default is the same as the default of t.isolines.

import { sketch, strokes } from 'occlude';

// One seed, no walls, but the ground is slow where the noise is low. The
// rings still leave the seed together; they bunch up over the slow ground
// and stretch where the going is easy.
export default sketch({ aspect: [1, 1], seed: 7 }, (t) => {
  const b = t.bounds();
  const going = (x, y) => 0.2 + 0.8 * (0.5 + 0.5 * t.noise(x / 24, y / 24));
  const arrival = t.travelTime({ fromPoints: [[b.cx, b.cy]], speed: going, step: 0.5 });
  return strokes(t.isolines(arrival, { spacing: b.w / 16 }));
});

translate() · rotate() · scale()

/_sig/translate.mdx /_sig/rotate.mdx /_sig/scale.mdx

Transforms of a field's sampling. translate moves it, rotate turns it, and scale scales it, with [sx, sy] for each axis. rotate and scale turn and scale about origin, a point. The user origin is the default. A field has no bounds, so it has no middle and no centroid: the call refuses 'center' and 'centroid' by name. For the middle of the drawable, give the point [t.bounds().cx, t.bounds().cy]. The result is a plain function again. Each disc below holds the plain field in black and the changed one in blue: moved, turned and scaled.

import { sketch, circle, strokes, translate, rotate, scale } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const stripes = (x, y) => Math.sin(x / 2.5);
  const disc = (cx, cy, f) => {
    const d = circle(cx, cy, 20);
    return [strokes(t.isolines(t.within(stripes, d), 0)), strokes(t.isolines(t.within(f, d), 0), { pen: 'stabilo-88-blue' }), d];
  };
  return [disc(27, 30, translate(stripes, 4, 0)), disc(73, 30, rotate(stripes, 30)), disc(50, 74, scale(stripes, 2))];
});

A vector field marked with vectorField turns its arrows too. A plain function gives no sign that it is a vector. The verb then moves where it samples and leaves the answer alone. Below, one east-pointing field under rotate(…, 45). The plain function (green) still points east. The marked one (blue) has turned.

import { sketch, line, circle, rotate, vectorField, add, mul } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const east = (x, y) => [1, 0];
  const plain = rotate(east, 45), marked = rotate(vectorField(east), 45);
  const arrow = (p, v, pen) => [circle(p, 0.8, { pen }), line(p, add(p, mul(v, 7)), { pen })];
  return t.grid({ cols: 5, rows: 5 }).faces.map((f) => {
    const [x, y] = f.centroid;
    return [
      arrow([x - 4, y - 2], plain(x, y), 'stabilo-88-green'),
      arrow([x - 4, y + 3], marked(x, y), 'stabilo-88-blue'),
    ];
  });
});

t.within()

/_sig/Toolkit.within.1.mdx /_sig/Toolkit.within.2.mdx /_sig/Toolkit.within.3.mdx /_sig/Toolkit.within.4.mdx

Keeps only what lies inside an area. A field becomes absent outside it, so generators make nothing there and contours stop at the edge. It cuts a material at the boundary. A material with faces closes along the boundary. The part of the area's edge that goes through a face becomes a wall of that face. These walls have the edge column cut = 1, and the other edges have cut = 0. The call replaces an existing cut column. A material without faces does not get the column. A corner of the area inside a face becomes a new vertex, with the columns of the vertex before it. An open chain stops at the boundary. To draw the material without the rim, filter the column. It filters a point selection, an edge selection or a face collection. area is an Area: a shape, a group, a face, a loop of pairs, a list of contours or a closed material. A group is the union of its shapes, and its transform applies. invert(area) is the area outside, in the drawable. The toolkit reads each area in the same way for every word that takes an area. A face collection is several areas, so the call refuses it and tells you to name one face. The call refuses a value that is not an area, and names it.

A selection cannot clip. A point, an edge and a face come through whole or not at all. The option keep decides, with the same three words for points, edges and faces. { keep: 'contained' } is the default. It keeps a member with no point outside the area and no crossing of the boundary. The boundary belongs to the area, so a point on the boundary is in, and a wall along the boundary is in. 'centroid' keeps a member whose centroid is in the area or on its boundary. The centroid of an edge is its center, and the centroid of a point is the point. 'touching' keeps a member that has a point in common with the area. This includes a face that holds all of the area. The call judges the boundary with the ink tolerance, 0.05 mm on the sheet. A vertex that is nearer than this to the boundary is on the boundary. The call refuses the old option names faces and edges, and names them. To cut at the boundary instead, give within the material.

Below, the black walls are contained. The blue walls are what centroid adds. Each one straddles the circle, so its ink reaches past the edge by up to half a wall.

import { sketch, strokes, circle, connect } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 8 }, (t) => {
  const web = connect.triangulate(t.scatter({ spacing: 11 }));
  const disc = circle(50, 50, 42);
  const whole = t.within(web.edges, disc);
  const cut = t.within(web.edges, disc, { keep: 'centroid' });
  return [
    strokes(whole),
    strokes(cut.without(whole), { pen: 'stabilo-88-blue' }),
    circle(50, 50, 42, { pen: 'stabilo-88-green' }),
  ];
});
import { sketch, circle, rect, strokes } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 2 }, (t) => {
  const stripes = (x, y) => Math.sin(x / 3);
  const disc = circle(30, 50, 24);
  const web = t.streamlines((x, y) => [1, 0.4 * Math.sin(y / 8)], { spacing: 4 });
  return [strokes(t.isolines(t.within(stripes, disc), 0)), circle(30, 50, 24, { pen: 'stabilo-88-blue' }), strokes(t.within(web, rect(62, 20, 34, 60))), rect(62, 20, 34, 60, { pen: 'stabilo-88-blue' })];
});

Below, a circle cuts a hexagon tiling. Each tile at the rim is a face, so polygon fills it. The walls draw without the rim.

import { sketch, strokes, circle, polygon, fill, mm } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const cells = t.within(t.tiling(6, 3, { side: 5.2, rotate: 30 }), circle(50, 50, 40));
  return [
    cells.faces.map((f, i) => polygon(f, { fill: fill('hatch', { angle: i % 2 ? 60 : -30, spacing: mm(1) }), stroke: false })),
    strokes(cells.edges.filter((e) => !e.cut)),
  ];
});

curl() · grad() · vectorField()

/_sig/curl.mdx /_sig/grad.mdx /_sig/vectorField.mdx

grad(f) is the gradient of a scalar field: it points uphill. curl(f) is the gradient turned 90°, so it runs along the contours of f. Both take central differences over { step }, 0.25 by default. vectorField(fn) marks your own vector function, so the field verbs turn its arrows too (see translate · rotate · scale). Below, the black marks point uphill from each dot, and the blue marks run along the contours.

import { sketch, line, circle, strokes, curl, grad, add, mul, unit } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const hill = (x, y) => t.noise(x / 30, y / 30);
  const marks = (vf, pen) => t.grid({ cols: 9, rows: 9 }).faces.map((f) => {
    const p = f.centroid;
    return [circle(p, 0.7, { pen }), line(p, add(p, mul(unit(vf(...p)), 5)), { pen })];
  });
  return [strokes(t.isolines(hill, [-0.4, -0.2, 0, 0.2, 0.4]), { pen: 'pigma-005-black' }), marks(grad(hill)), marks(curl(hill), 'stabilo-88-blue')];
});

t.streamlines()

/_sig/Toolkit.streamlines.mdx

Evenly spaced flow lines of a vector field, as one material of open chains. A line stops at the edge of the drawable, at a within bound, and half a spacing from other lines. Lines never cross or bunch. spacing is a length or a field of lengths. A field of lengths turns density into tone. The result does not read the seed.

import { sketch, strokes, curl, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 4 }, (t) => strokes(t.streamlines(curl((x, y) => t.noise(x / 35, y / 35)), { spacing: mm(2.5) })));

Each point of a line has u, its fraction of the arc length along its own line. u is 0 at the start of the line and 1 at its end. A long line and a short line both go from 0 to 1. Below, the first half of each line is blue.

import { sketch, strokes, curl, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 4 }, (t) => {
  const lines = t.streamlines(curl((x, y) => t.noise(x / 35, y / 35)), { spacing: mm(2.5) });
  return [strokes(lines.edges.filter((e) => e.b.u > 0.5)), strokes(lines.edges.filter((e) => e.b.u <= 0.5), { pen: 'stabilo-88-blue' })];
});

maxLength is the longest run each way from a seed. It is a length, or a field of lengths read at the seed, so one seed grows one mark of that length. A seed whose length is zero, absent, or below a nib width draws nothing, because the pen would leave a dot there. Length is then a second tone beside spacing. The marks of an engraving run long in the dark. They shorten through the mid tones, and they end as dots in the light.

import { sketch, strokes, mm } from 'occlude';

export default sketch({ aspect: [1, 1] }, (t) => {
  const img = t.image('ivy.png', { x: 8, y: 2, width: 84 });
  const dark = img.field('dark', { area: 1 });
  const ink = (x, y) => img.a(x, y) * dark(x, y);
  return strokes(t.streamlines(img.flow({ radius: 3 }), {
    spacing: (x, y) => mm(0.9 + 2.4 * (1 - ink(x, y))),
    maxLength: (x, y) => mm(img.a(x, y) * (0.45 + 34 * ink(x, y) ** 3)),
  }));
});

axisField() · across()

/_sig/axisField.mdx /_sig/across.mdx

axisField(fn) marks a direction field as unoriented. The sign carries no meaning: [dx, dy] and [-dx, -dy] are the same axis. t.streamlines keeps the sign it started with along a line, so the line crosses a place where the formula changes sign. An oriented field stops there instead. The verbs rotate, translate, scale and t.within keep the mark. across(field) is the family at a right angle. An axis field gives an axis field, and a vector field gives a turned vector field. The example reads the slope of a noise landscape as an axis. One hatch crosses each hill and each hollow without a break, and across weaves the second family over it.

import { sketch, strokes, axisField, across, grad, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 5 }, (t) => {
  const slope = axisField(grad((x, y) => t.noise(x / 46, y / 46), { step: 1 }));
  return [
    strokes(t.streamlines(slope, { spacing: mm(3) }), { pen: 'pigma-01-black' }),
    strokes(t.streamlines(across(slope), { spacing: mm(6) }), { pen: 'stabilo-88-green' }),
  ];
});

t.ridges()

/_sig/Toolkit.ridges.mdx

The crest lines of a scalar field: where the field is at a maximum across the line. Contours show where the field is at a height. Ridges show where it runs along a top. Each crest is a chain, and each vertex carries strength, how sharply the ground falls to either side, and height. The result has no threshold. Filter by strength (see Selections) to keep the crests that earn ink. Valleys are the ridges of the negated field.

import { sketch, strokes } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 6 }, (t) => {
  const ground = (x, y) => t.noise(x / 22, y / 22);
  const crests = t.ridges(ground);
  return [strokes(t.isolines(ground, [-0.3, 0, 0.3]), { pen: 'stabilo-88-blue' }), strokes(crests.points.filter((p) => p.strength > 0.004).edges)];
});

t.lattice()

/_sig/Toolkit.lattice.mdx

A grid of square faces over an area, with named channels. spacing sets the face size. area defaults to the drawable, and channels defaults to ['a']. init fills each face from its centre.

A lattice is one table of faces, and lat.faces.set(channel, value, where?) writes a channel. lat.faces holds the faces. A face answers the words of every face, such as centroid, bounds and adjacent. It also answers its grid place i and j, every channel by name, and c.laplacian(channel) (the five-point stencil). t.steps(n, lat, pass) runs a pass over it. Every function of one set reads the faces as they were before the write. So one write over the whole grid is one instant. A diffusion is one write: lat.faces.set('a', (c) => c.a + rate * c.laplacian('a')). A rate above 0.25 runs away. A decay is lat.faces.set('a', (c) => c.a * (1 - rate)). The steps page tells more about the lattice as one table.

lat.add(points, amount, channel?) puts an amount into the face under each point. lat.field(channel) reads a channel back as a field. lat.face([x, y]) is the face under a position. lat.values, lat.cols and lat.rows give the raw numbers. Every operation returns a new value.

Below, ink drops at a few points and spreads. Each step diffuses the channel and then forgets a little of it.

import { sketch, strokes, dots, mm, pen } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 5, pens: { ink: pen({ width: mm(0.25), color: '#23252B' }), drop: pen({ width: mm(1.2), color: '#2457D6' }) } }, (t) => {
  const drops = t.throw({ count: 12 });
  const spread = (l) => l.faces.set('a', (c) => c.a + 0.22 * c.laplacian('a')).faces.set('a', (c) => c.a * 0.99);
  const ink = t.steps(90, t.lattice({ spacing: 1 }).add(drops, 60), spread);
  return [strokes(t.isolines(ink.field(), [0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64])), dots(drops, { pen: 'drop' })];
});

t.residual()

/_sig/Toolkit.residual.mdx

The tone a drawing still owes, as a lattice with one channel, owed. field is the target darkness, 0 to 1. spacing is the face size. area says what owes anything. r.field() is the debt as a field, so t.scatter, t.isolines and a decimate amount read it. Outside the area the field is NaN, and a field consumer reads that as no place.

r.spend(marks, { width }) takes away the nib footprint of the marks and returns a new lattice. marks is a material, a selection, a contour, a list of contours or a polyline. A chain costs its stroke at width, and a loose point costs a dot. width is a length in the units of the lattice, because a lattice does not know the paper. Give a nib as t.len(mm(0.35)). A face never goes below 0. r.faces.sum('owed') is the debt that remains. What a spend took is the drop in that sum, in face areas.

Nothing changes in place. A ledger is a sequence of values, r = r.spend(…). Each earlier value still reads what it read before, so keep one when you need the debt at that time.

Two pens against one debt. The broad pen stipples first and pays for what its nib covers. The fine pen then fills only the tone that the broad pen missed.

import { sketch, dots, pen, mm, distance } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 3, pens: {
  broad: pen({ width: mm(3), color: '#B4ADA3' }),
  fine: pen({ width: mm(0.4), color: '#23252B' }),
} }, (t) => {
  const tone = (x, y) => Math.max(0, Math.min(1, 1.2 - distance([x, y], [50, 50]) / 40));
  let r = t.residual(tone, { spacing: mm(3) });
  const broad = t.scatter(r.field(), { spacing: mm(5) });
  r = r.spend(broad, { width: t.len(mm(3)) });
  const fine = t.scatter(r.field(), { spacing: mm(0.9) });
  return [dots(broad, { pen: 'broad' }), dots(fine, { pen: 'fine' })];
});

t.spacefill()

/_sig/Toolkit.spacefill.mdx

One line that folds until the folds fill an area. It visits every cell of a divided square once. The line is one stroke when the area is that square: a side of spacing times a power of the rule's n. Any other area breaks the stroke where cells fall outside it. spacing is the finest cell. A field of tone, 0 to 1, divides a cell again where the tone asks for a finer cell. Tone 0 lifts the pen. maxSpacing caps the coarsest cell. Each vertex carries the level it stopped at. area takes a shape, a face, loops or a contour material.

rule is the fold as data: how a cell divides, the order of its children, and the turn each one takes. hilbertRule is the default. peanoRule and meanderRule divide in threes. A table that misses a cell refuses by name.

import { sketch, strokes, rect, peanoRule, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 4 }, (t) => {
  const tone = (x, y) => (t.noise(x / 26, y / 26) + 1) / 2;
  return strokes(t.spacefill(rect(6, 6, 88, 88), { spacing: mm(1.6), field: tone, rule: peanoRule }));
});

complex · escape()

/_sig/escape.mdx

A field made of an iteration. step is your own map (z, c) => z' over [x, y] pairs. opts takes input, iterations and bailout. The complex namespace has the arithmetic: add, sub, mul, div, exp, log, pow, sqrt and polar. The field answers the smooth count of steps before z escapes, so its contours do not step. field.potential answers log|z| / degree^n. A point that never escapes answers NaN, and every field consumer reads NaN as no place. input: 'c' reads the sheet as c (the Mandelbrot set). input: 'z' with a fixed c reads it as z (a Julia set).

import { sketch, strokes, escape, complex, pen, mm } from 'occlude';

export default sketch({ aspect: [1, 1], seed: 21, pens: {
  fine: pen({ width: mm(0.3), color: '#8A857C' }),
  heavy: pen({ width: mm(1), color: '#23252B' }),
} }, (t) => {
  const step = (z, c) => complex.add(complex.mul(z, z), c);
  const field = escape(step, { input: 'c', iterations: 60, bailout: 1e6 });
  // The sheet as the c-plane: (64, 50) is c = 0, and 34 sheet units are one unit of c.
  const count = (x, y) => field((x - 64) / 34, (y - 50) / 34);
  return [
    strokes(t.isolines(count, { spacing: 1 }), { pen: 'fine' }),
    strokes(t.isolines(count, { spacing: 5 }), { pen: 'heavy' }),
  ];
});