Public
Edited
Oct 1, 2023
Fork of Spectre
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
WIDTH = Math.min(800, width)
Insert cell
HEIGHT = 500
Insert cell
ORIGIN = [0,0,-250,0]
Insert cell
Insert cell
Insert cell
Insert cell
FINETUNE_DEGREES = 9
Insert cell
Insert cell
Insert cell
Insert cell
HEX_SIDE = L/2 * Math.sqrt((2 + 2/SQRT3) * (1 + 1 / (Math.sqrt(15) + 4)));
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function makeCluster(type, pt, rot) {
const tiles = [];

let pts1, pts3, pts5, pts6, pts7;
tiles.push(pts5 = tile('Γ1', pt, 0, 3, rot)); // 5
tiles.push(tile('Γ2', pts5[9], 5, 4, rot)); // 8
tiles.push(pts6 = tile(TILE6[type], pts5[1], 11, 0, rot)); // 6
tiles.push(tile('Δ', pts5[1], 13, 2, rot)); // 2
tiles.push(pts1 = tile(TILE1[type], pts5[5], 11, 4, rot)); // 1
tiles.push(tile('Σ', pts5[5], 13, 6, rot)); // 4
tiles.push(pts7 = tile(TILE7[type], pts5[9], 11, 8, rot)); // 7
tiles.push(pts3 = tile(TILE3[type], pts6[6], 0, 2, rot)); // 3

if (type !== 'Γ') {
tiles.push(tile(TILE9[type], tiles[4][6], 0, 6, rot)); // 9
}

const control_points = [
pts1[4],
pts7[6],
pts6[4],
pts3[6],
];
return {
tiles,
control_points
};
}
Insert cell
Insert cell
Insert cell
function makeSupercluster(type, pt, r) {
const c1 = makeCluster('Γ', pt, 11 + r);
const c2 = makeCluster(TILE6[type][0], c1.control_points[1], 3 + r);
translate(c2.control_points[1], c1.control_points[1], c2);

const c3 = makeCluster(TILE7[type], c1.control_points[2], 7 + r);
translate(c3.control_points[2], c1.control_points[2], c3);

const c4 = makeCluster('Δ', c3.control_points[1], 9 + r);
translate(c4.control_points[3], c3.control_points[1], c4);

// If type == 'Γ' then this cluster is not real, but we need to
// make some random 9-cluster just to get the control point,
// so I chose Ξ arbitrarily.
//
// We could avoid this by starting the chain in a different place.
const c5 = makeCluster(type == 'Γ' ? 'Ξ' : TILE9[type], c4.control_points[0], 9 + r);
translate(c5.control_points[2], c4.control_points[0], c5);

const c6 = makeCluster(TILE1[type][0], c5.control_points[1], 11 + r);
translate(c6.control_points[3], c5.control_points[1], c6);

const c7 = makeCluster('Σ', c6.control_points[1], 1 + r);
translate(c7.control_points[3], c6.control_points[1], c7);

const c8 = makeCluster(TILE3[type], c7.control_points[0], 1 + r);
translate(c8.control_points[2], c7.control_points[0], c8);

let tiles;
if (type == 'Γ') {
tiles = c1.tiles.concat(
c2.tiles,
c3.tiles,
c4.tiles,
c6.tiles,
c7.tiles,
c8.tiles,
);
}
else {
tiles = c1.tiles.concat(
c2.tiles,
c3.tiles,
c4.tiles,
c5.tiles,
c6.tiles,
c7.tiles,
c8.tiles,
);
}

return {
control_points: [
c6.control_points[0],
c3.control_points[3],
c2.control_points[0],
c8.control_points[3],
],
tiles
};
}
Insert cell
function makeHypercluster(type, pt, r) {
const s1 = makeSupercluster('Γ', pt, 0 + r);

const s2 = makeSupercluster(TILE6[type][0], s1.control_points[1], 8 + r);
translate(s2.control_points[1], s1.control_points[1], s2);

const s3 = makeSupercluster(TILE7[type], s1.control_points[2], 4 + r);
translate(s3.control_points[2], s1.control_points[2], s3);

const s4 = makeSupercluster('Δ', s3.control_points[1], 2 + r);
translate(s4.control_points[3], s3.control_points[1], s4);

const s5 = makeSupercluster(type == 'Γ' ? 'Ξ' : TILE9[type], s4.control_points[0], 2 + r);
translate(s5.control_points[2], s4.control_points[0], s5);

const s6 = makeSupercluster(TILE1[type][0], s5.control_points[1], 0 + r);
translate(s6.control_points[3], s5.control_points[1], s6);

const s7 = makeSupercluster('Σ', s6.control_points[1], 10 + r);
translate(s7.control_points[3], s6.control_points[1], s7);

const s8 = makeSupercluster(TILE3[type], s7.control_points[0], 10 + r);
translate(s8.control_points[2], s7.control_points[0], s8);

let tiles;
if (type == 'Γ') {
tiles = s1.tiles.concat(
s2.tiles,
s3.tiles,
s4.tiles,
s6.tiles,
s7.tiles,
s8.tiles,
);
}
else {
tiles = s1.tiles.concat(
s2.tiles,
s3.tiles,
s4.tiles,
s5.tiles,
s6.tiles,
s7.tiles,
s8.tiles,
);
}

return {
control_points: [
s6.control_points[0],
s3.control_points[3],
s2.control_points[0],
s8.control_points[3],
],
tiles
};
}
Insert cell
{
const ct = canvas.ct;

ct.clearRect(-canvas.width/2, -canvas.height/2, canvas.width, canvas.height);
ct.strokeStyle = 'white';

const type = 'Λ';

const h1 = makeHypercluster('Γ', ORIGIN, 0);

const h2 = makeHypercluster(TILE6[type][0], h1.control_points[1], 4);
translate(h2.control_points[1], h1.control_points[1], h2);

const h3 = makeHypercluster(TILE7[type], h1.control_points[2], 8);
translate(h3.control_points[2], h1.control_points[2], h3);

const h4 = makeHypercluster('Δ', h3.control_points[1], 10);
translate(h4.control_points[3], h3.control_points[1], h4);

const h5 = makeHypercluster(type == 'Γ' ? 'Ξ' : TILE9[type], h4.control_points[0], 10);
translate(h5.control_points[2], h4.control_points[0], h5);

const h6 = makeHypercluster(TILE1[type][0], h5.control_points[1], 0);
translate(h6.control_points[3], h5.control_points[1], h6);

const h7 = makeHypercluster('Σ', h6.control_points[1], 2);
translate(h7.control_points[3], h6.control_points[1], h7);

const h8 = makeHypercluster(TILE3[type], h7.control_points[0], 2);
translate(h8.control_points[2], h7.control_points[0], h8);

ct.strokeStyle = 'white';
for (const spectre of h1.tiles) draw(ct, spectre);
for (const spectre of h2.tiles) draw(ct, spectre);
for (const spectre of h3.tiles) draw(ct, spectre);
for (const spectre of h4.tiles) draw(ct, spectre);
for (const spectre of h5.tiles) draw(ct, spectre);
for (const spectre of h6.tiles) draw(ct, spectre);
for (const spectre of h7.tiles) draw(ct, spectre);
for (const spectre of h8.tiles) draw(ct, spectre);

return this || html`(<i>the drawing function</i>)`;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more