viewof illo = {
const context = DOM.context2d(width, height, 1),
element = context.canvas;
const X = d3
.scaleLinear()
.domain([0, data.width])
.range([-width / 2, width / 2]),
Y = d3
.scaleLinear()
.domain([0, data.height])
.range([-height / 2, height / 2]),
H = (x, y) => tin.heightAt(Math.round(x), Math.round(y)),
Z = (x, y) => 2 * (H(x, y) - 100);
const illo = (element.value = new Zdog.Illustration({
element,
dragRotate: true,
onDragMove: update,
rotate: { x: Zdog.TAU * -.1 }
}));
const g = new Zdog.Anchor({addTo: illo, rotate: {x: Zdog.TAU / 4}});
for (let i = 0; i < tin.triangles.length; i += 3) {
const p0 = tin.triangles[i],
p1 = tin.triangles[i + 1],
p2 = tin.triangles[i + 2],
x0 = tin.coords[2 * p0],
y0 = tin.coords[2 * p0 + 1],
x1 = tin.coords[2 * p1],
y1 = tin.coords[2 * p1 + 1],
x2 = tin.coords[2 * p2],
y2 = tin.coords[2 * p2 + 1];
new Zdog.Shape({
addTo: g,
path: [
{ x: X(x0), y: Y(y0), z: Z(x0, y0) },
{ x: X(x1), y: Y(y1), z: Z(x1, y1) },
{ x: X(x2), y: Y(y2), z: Z(x2, y2) }
],
color: color(H((x0 + x1 + x2) / 3, (y0 + y1 + y2) / 3)),
stroke: 1,
fill: true
});
}
function update() {
illo.updateRenderGraph();
}
update();
yield element;
}