Public
Edited
Apr 29, 2024
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hexagons = {
regen;
const cells = [];
const alive = new Map();
const baseCells = h3.getRes0Cells();

// First pass, populate grid
for (const baseCell of baseCells) {
const childCount = h3.cellToChildrenSize(baseCell, h3Resolution);
for (let childPos = 0; childPos < childCount; childPos++) {
const cell = h3.childPosToCell(childPos, baseCell, h3Resolution);
cells.push(cell);
alive.set(cell, Math.random() < 0.3 ? 1 : 0);
}
}

function getState(cell) {
const isAlive = alive.get(cell);
const neighbors = h3.gridDisk(cell, 1);
let livingNeighbors = 0;
for (const neighbor of neighbors) {
if (neighbor !== cell && alive.get(neighbor)) livingNeighbors++;
}
if (isAlive) {
if (livingNeighbors <= underpop) return 0;
if (livingNeighbors >= overpop) return 0;
} else if (livingNeighbors > generation) {
return 1;
}
return isAlive;
}

while (true) {
await Promises.delay(200);
// next cycle
for (const cell of cells) {
alive.set(cell, getState(cell));
}
yield {cells, alive};
}
}
Insert cell
features = {
const features = {
type: 'FeatureCollection',
features: hexagons.cells.map((cell) => ({
type: 'Feature',
properties: {
alive: hexagons.alive.get(cell)
},
geometry: {
type: 'Polygon',
coordinates: [h3.cellToBoundary(cell, true)]
}
}))
};
fixTransmeridian(features);
return features;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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