Improve docs

This commit is contained in:
arne 2024-07-19 10:52:38 +02:00
commit 917e8297b9

View file

@ -1,6 +1,6 @@
import { line, group, translate, asSvg, svgDoc } from "@thi.ng/geom";
import { line, group, translate, asSvg, svgDoc, scale } from "@thi.ng/geom";
import { $canvas } from "@thi.ng/rdom-canvas";
import { reactive, sync, } from "@thi.ng/rstream";
import { reactive, sync } from "@thi.ng/rstream";
import { $compile, $input } from '@thi.ng/rdom'
import { cycle, takeWhile, comp, mapIndexed, range, iterator, map, mapcat } from "@thi.ng/transducers"
import { vec2 } from "@thi.ng/vectors"
@ -24,9 +24,10 @@ const height = 594
const size = [width, height]
// build a list of start positions
// build a list of start positions in a one-dimensional grid; lines will start
// perpendicular from the first value (cell index) with a given seed (1 or 0)
const startPoints = (pattern: Iterable<number>, maxCells: number) =>
const seededGrid = (pattern: Iterable<number>, maxCells: number) =>
[...iterator(
comp(
mapIndexed((cell, val) => [cell, val] as const),
@ -35,7 +36,7 @@ const startPoints = (pattern: Iterable<number>, maxCells: number) =>
cycle(pattern)
)]
// points from which to which a stitch is showing for a given seed (1 or 0)
// points from which to which a stitch is showing for a given seed
const stitches = (seed: number, maxCells: number) =>
[...iterator(
@ -62,19 +63,19 @@ const scene = sync({
const yCells = Math.floor((height - 2 * minPadding) / cellSize)
const yPadding = (height - (yCells * cellSize)) / 2
const xStarts = startPoints(xs, xCells)
const yStarts = startPoints(ys, yCells)
const xSeeds = seededGrid(xs, xCells)
const ySeeds = seededGrid(ys, yCells)
const yLines = iterator(
mapcat(([x, seed]) =>
map(([y1, y2]) => line([x * cellSize, y1 * cellSize], [x * cellSize, y2 * cellSize]), stitches(seed, yCells))),
xStarts
map(([y1, y2]) => scale(line([x, y1], [x, y2]), cellSize), stitches(seed, yCells))),
xSeeds
)
const xLines = iterator(
mapcat(([y, seed]) =>
map(([x1, x2]) => line([x1 * cellSize, y * cellSize], [x2 * cellSize, y * cellSize]), stitches(seed, xCells))),
yStarts
map(([x1, x2]) => scale(line([x1, y], [x2, y]), cellSize), stitches(seed, xCells))),
ySeeds
)
const scene = translate(