Published
Edited
Jan 27, 2020
1 fork
Insert cell
Insert cell
import {slider} from "@jashkenas/inputs";
Insert cell
import {xySlider} from "98bbb19bf9e859ee";
Insert cell
Insert cell
viewof k = slider({ min: 0, max: 4, value: 4 });
Insert cell
Insert cell
x0 = x0y0[0]; //Math.min(x0y0[0], x1);
Insert cell
y0 = x0y0[1]; //Math.min(x0y0[1], y1);
Insert cell
Insert cell
parts = {
// Thanks J. Amanatides, A. Woo. A Fast Voxel Traversal Algorithm for Ray Tracing. Eurographics '87
// Thanks https://github.com/francisengelmann/fast_voxel_traversal/blob/master/main.cpp
const parts = [];
let X = Math.floor(x0/(1/d));
let Y = Math.floor(y0/(1/d));
let FX = Math.floor(x1/(1/d));
let FY = Math.floor(y1/(1/d));
const stepX = x1 > x0 ? 1 : -1;
const stepY = y1 > y0 ? 1 : -1;
const dx = x1 - x0;
const dy = y1 - y0;
const nextX = (X+stepX)*(1/d);
const nextY = (Y+stepY)*(1/d);
let tMaxX = (nextX - x0) / dx;
let tMaxY = (nextY - y0) / dy;
const tDeltaX = (1/d) / dx * stepX;
const tDeltaY = (1/d) / dy * stepY;
parts.push({ x: X/d, y: Y/d });
for (let iii=0; iii<maxIter && !(X == FX && Y == FY); ++iii) {
let f;
if (tMaxX < tMaxY) {
tMaxX += tDeltaX;
X += stepX;
f = false;
} else {
tMaxY += tDeltaY;
Y += stepY;
f = true;
}
parts.push({ x: X/d, y: Y/d, f });
}
return parts;
};
Insert cell
function ceil(n) {
if (n % (1/d) < 0.001) return n;
return n + (1/d - n % (1/d));
}
Insert cell
function floor(n) {
return n - (n % (1/d));
}
Insert cell
{
return [temp, floor(temp), ceil(temp)];
}
Insert cell
viewof temp = slider({ min: 0, max: 1 });
Insert cell
d = Math.pow(2, k)
Insert cell
x1 = .7;
Insert cell
y1 = .8;
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more