Improve docs
This commit is contained in:
parent
a846f38f61
commit
917e8297b9
1 changed files with 12 additions and 11 deletions
23
src/main.ts
23
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 { $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 { $compile, $input } from '@thi.ng/rdom'
|
||||||
import { cycle, takeWhile, comp, mapIndexed, range, iterator, map, mapcat } from "@thi.ng/transducers"
|
import { cycle, takeWhile, comp, mapIndexed, range, iterator, map, mapcat } from "@thi.ng/transducers"
|
||||||
import { vec2 } from "@thi.ng/vectors"
|
import { vec2 } from "@thi.ng/vectors"
|
||||||
|
|
@ -24,9 +24,10 @@ const height = 594
|
||||||
|
|
||||||
const size = [width, height]
|
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(
|
[...iterator(
|
||||||
comp(
|
comp(
|
||||||
mapIndexed((cell, val) => [cell, val] as const),
|
mapIndexed((cell, val) => [cell, val] as const),
|
||||||
|
|
@ -35,7 +36,7 @@ const startPoints = (pattern: Iterable<number>, maxCells: number) =>
|
||||||
cycle(pattern)
|
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) =>
|
const stitches = (seed: number, maxCells: number) =>
|
||||||
[...iterator(
|
[...iterator(
|
||||||
|
|
@ -62,19 +63,19 @@ const scene = sync({
|
||||||
const yCells = Math.floor((height - 2 * minPadding) / cellSize)
|
const yCells = Math.floor((height - 2 * minPadding) / cellSize)
|
||||||
const yPadding = (height - (yCells * cellSize)) / 2
|
const yPadding = (height - (yCells * cellSize)) / 2
|
||||||
|
|
||||||
const xStarts = startPoints(xs, xCells)
|
const xSeeds = seededGrid(xs, xCells)
|
||||||
const yStarts = startPoints(ys, yCells)
|
const ySeeds = seededGrid(ys, yCells)
|
||||||
|
|
||||||
const yLines = iterator(
|
const yLines = iterator(
|
||||||
mapcat(([x, seed]) =>
|
mapcat(([x, seed]) =>
|
||||||
map(([y1, y2]) => line([x * cellSize, y1 * cellSize], [x * cellSize, y2 * cellSize]), stitches(seed, yCells))),
|
map(([y1, y2]) => scale(line([x, y1], [x, y2]), cellSize), stitches(seed, yCells))),
|
||||||
xStarts
|
xSeeds
|
||||||
)
|
)
|
||||||
|
|
||||||
const xLines = iterator(
|
const xLines = iterator(
|
||||||
mapcat(([y, seed]) =>
|
mapcat(([y, seed]) =>
|
||||||
map(([x1, x2]) => line([x1 * cellSize, y * cellSize], [x2 * cellSize, y * cellSize]), stitches(seed, xCells))),
|
map(([x1, x2]) => scale(line([x1, y], [x2, y]), cellSize), stitches(seed, xCells))),
|
||||||
yStarts
|
ySeeds
|
||||||
)
|
)
|
||||||
|
|
||||||
const scene = translate(
|
const scene = translate(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue