diff --git a/src/main.ts b/src/main.ts index ee83786..e4f202c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,8 +1,8 @@ -import { line, group, translate, asSvg, svgDoc, scale } from "@thi.ng/geom"; +import { line, group, translate, asSvg, svgDoc, scale, flip } from "@thi.ng/geom"; import { $canvas } from "@thi.ng/rdom-canvas"; import { reactive, sync } from "@thi.ng/rstream"; 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, reverse } from "@thi.ng/transducers" import { vec2 } from "@thi.ng/vectors" const cellSize_ = "12" @@ -71,8 +71,19 @@ const scene = sync({ const ySeeds = seededGrid(ys, yCells) const yLines = iterator( - mapcat(([x, seed]) => - map(([y1, y2]) => scale(line([x, y1], [x, y2]), cellSize), stitches(seed, yCells))), + mapcat(([x, seed]) => { + // optimization for quicker drawing: when we're in an odd row, + // reverse drawing direction + const inEvenRow = x % 2 === 0 + return iterator( + comp( + map(([y1, y2]) => line([x, y1], [x, y2])), + map(l => inEvenRow ? l : flip(l)), + map(l => scale(l, cellSize)) + ), + inEvenRow ? stitches(seed, yCells) : reverse(stitches(seed, yCells)) + ) + }), xSeeds )