Published
Edited
Jul 25, 2019
2 forks
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
color = i => d3.rgb(d3.interpolateRainbow(i / (n * n)))
Insert cell
function xy2d(x, y) {
let rx, ry, s, d = 0;
for (s = n >> 1; s > 0; s >>= 1) {
rx = (x & s) > 0;
ry = (y & s) > 0;
d += s * s * ((3 * rx) ^ ry);
[x, y] = rot(n, x, y, rx, ry);
}
return d;
}
Insert cell
function d2xy(d) {
let rx, ry, s, t = d;
let x = 0, y = 0;
for (s = 1; s < n; s <<= 1) {
rx = 1 & (t >> 1);
ry = 1 & (t ^ rx);
[x, y] = rot(s, x, y, rx, ry);
x += s * rx;
y += s * ry;
t >>= 2;
}
return [x, y];
}
Insert cell
function rot(n, x, y, rx, ry) {
if (!ry) {
if (rx) {
x = n - 1 - x;
y = n - 1 - y;
}
return [y, x];
}
return [x, y];
}
Insert cell
z = 9
Insert cell
n = Math.pow(2, z)
Insert cell
n2 = Math.pow(2, z * 2)
Insert cell
d3 = require("d3-color@1", "d3-scale-chromatic@1")
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