From 917e8297b9e4502fd9d555190e7036b7b669c5b2 Mon Sep 17 00:00:00 2001 From: arne Date: Fri, 19 Jul 2024 10:52:38 +0200 Subject: [PATCH] Improve docs --- src/main.ts | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main.ts b/src/main.ts index 2283a2a..398dc04 100644 --- a/src/main.ts +++ b/src/main.ts @@ -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, maxCells: number) => +const seededGrid = (pattern: Iterable, maxCells: number) => [...iterator( comp( mapIndexed((cell, val) => [cell, val] as const), @@ -35,7 +36,7 @@ const startPoints = (pattern: Iterable, 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(