diff --git a/src/main.ts b/src/main.ts index 934d9ee..0af0054 100644 --- a/src/main.ts +++ b/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)