Shuffling things around
This commit is contained in:
parent
dfb4b08c35
commit
07c61fed6a
1 changed files with 15 additions and 14 deletions
29
src/main.ts
29
src/main.ts
|
|
@ -3,7 +3,7 @@ import { vec2, type Vec2 } from "@thi.ng/vectors"
|
|||
import { $canvas } from "@thi.ng/rdom-canvas";
|
||||
import { reactive, sync } from "@thi.ng/rstream";
|
||||
import { $compile, $input, $inputNum } from '@thi.ng/rdom'
|
||||
import { cycle, comp, range, iterator, map, mapcat, reverse, zip } from "@thi.ng/transducers"
|
||||
import { cycle, comp, range, iterator, map, mapcat, reverse, zip, filter } from "@thi.ng/transducers"
|
||||
|
||||
// initial settings
|
||||
|
||||
|
|
@ -50,10 +50,10 @@ const secondaryColor = getComputedStyle(document.documentElement).getPropertyVal
|
|||
|
||||
const stitches = (seed: number, maxCoord: number) =>
|
||||
iterator(
|
||||
mapcat((cell) => (cell + seed) % 2 === 0 // start at the beginning or skip it
|
||||
? [vec2(cell, cell + 1)]
|
||||
: null)
|
||||
,
|
||||
comp(
|
||||
filter((cell) => (cell + seed) % 2 === 0), // start at the beginning or skip it
|
||||
map((cell) => vec2(cell, cell + 1))
|
||||
),
|
||||
range(maxCoord)
|
||||
)
|
||||
|
||||
|
|
@ -62,18 +62,19 @@ const yLineGen = (coord: number, [p1, p2]: Vec2) => line([coord, p1], [coord, p2
|
|||
|
||||
const generateLines = (maxCoordOnAxis: number, maxCoordPerpendicular: number, seeds: Iterable<number>, lineGen: (coord: number, l: Vec2) => Line) =>
|
||||
iterator(
|
||||
mapcat(([coord, seed]) => {
|
||||
comp(
|
||||
map(([coord, seed]) => [coord, stitches(seed, maxCoordPerpendicular)] as const),
|
||||
// optimization for quicker drawing: when we're in an odd row / col,
|
||||
// reverse drawing direction
|
||||
const onEvenCoord = coord % 2 === 0
|
||||
return iterator(
|
||||
comp(
|
||||
map(l => lineGen(coord, l)),
|
||||
map(l => onEvenCoord ? l : flip(l))
|
||||
),
|
||||
onEvenCoord ? stitches(seed, maxCoordPerpendicular) : reverse(stitches(seed, maxCoordPerpendicular))
|
||||
mapcat(([coord, stitches]) =>
|
||||
map(
|
||||
l => lineGen(coord, l),
|
||||
coord % 2 === 0
|
||||
? stitches
|
||||
: reverse(map(([p1, p2]) => vec2(p2, p1), stitches))
|
||||
)
|
||||
}),
|
||||
)
|
||||
),
|
||||
zip(range(maxCoordOnAxis + 1), seeds)
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue