Improve zigzaging
This commit is contained in:
parent
59ec67e850
commit
1268e4811a
1 changed files with 6 additions and 10 deletions
16
src/main.ts
16
src/main.ts
|
|
@ -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 { $canvas } from "@thi.ng/rdom-canvas";
|
||||
import { reactive, sync } from "@thi.ng/rstream";
|
||||
|
|
@ -66,15 +66,11 @@ const generateLines = (maxCoordOnAxis: number, maxCoordPerpendicular: number, se
|
|||
iterator(
|
||||
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
|
||||
mapcat(([coord, stitches]) =>
|
||||
map(
|
||||
l => lineGen(coord, l),
|
||||
coord % 2 === 0
|
||||
? stitches
|
||||
: reverse(map(([p1, p2]) => vec2(p2, p1), stitches))
|
||||
)
|
||||
// optimization for faster drawing: alternate drawing directions to
|
||||
// minimize pen movements
|
||||
mapcat(([coord, stitches]) => coord % 2 === 0
|
||||
? map(l => lineGen(coord, l), stitches)
|
||||
: map(l => flip(lineGen(coord, l)), reverse(stitches))
|
||||
)
|
||||
),
|
||||
zip(range(maxCoordOnAxis + 1), seeds)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue