Improve zigzaging

This commit is contained in:
arne 2024-07-21 01:15:07 +02:00
commit 1268e4811a

View file

@ -1,4 +1,4 @@
import { line, type Line, group, translate, asSvg, svgDoc, scale } from "@thi.ng/geom"; import { line, type Line, group, translate, asSvg, svgDoc, scale, flip } from "@thi.ng/geom";
import { vec2, type Vec2 } from "@thi.ng/vectors" import { vec2, type Vec2 } from "@thi.ng/vectors"
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";
@ -66,15 +66,11 @@ const generateLines = (maxCoordOnAxis: number, maxCoordPerpendicular: number, se
iterator( iterator(
comp( comp(
map(([coord, seed]) => [coord, stitches(seed, maxCoordPerpendicular)] as const), map(([coord, seed]) => [coord, stitches(seed, maxCoordPerpendicular)] as const),
// optimization for quicker drawing: when we're in an odd row / col, // optimization for faster drawing: alternate drawing directions to
// reverse drawing direction // minimize pen movements
mapcat(([coord, stitches]) => mapcat(([coord, stitches]) => coord % 2 === 0
map( ? map(l => lineGen(coord, l), stitches)
l => lineGen(coord, l), : map(l => flip(lineGen(coord, l)), reverse(stitches))
coord % 2 === 0
? stitches
: reverse(map(([p1, p2]) => vec2(p2, p1), stitches))
)
) )
), ),
zip(range(maxCoordOnAxis + 1), seeds) zip(range(maxCoordOnAxis + 1), seeds)