Start optimizing drawing instructions
This commit is contained in:
parent
1963471791
commit
07ca1a0a63
1 changed files with 15 additions and 4 deletions
19
src/main.ts
19
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 { $canvas } from "@thi.ng/rdom-canvas";
|
||||||
import { reactive, sync } from "@thi.ng/rstream";
|
import { reactive, sync } from "@thi.ng/rstream";
|
||||||
import { $compile, $input } from '@thi.ng/rdom'
|
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"
|
import { vec2 } from "@thi.ng/vectors"
|
||||||
|
|
||||||
const cellSize_ = "12"
|
const cellSize_ = "12"
|
||||||
|
|
@ -71,8 +71,19 @@ const scene = sync({
|
||||||
const ySeeds = seededGrid(ys, yCells)
|
const ySeeds = seededGrid(ys, yCells)
|
||||||
|
|
||||||
const yLines = iterator(
|
const yLines = iterator(
|
||||||
mapcat(([x, seed]) =>
|
mapcat(([x, seed]) => {
|
||||||
map(([y1, y2]) => scale(line([x, y1], [x, y2]), cellSize), stitches(seed, yCells))),
|
// 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
|
xSeeds
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue