Published
Edited
Oct 4, 2019
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d_a = 1
Insert cell
d_b = 0.5
Insert cell
feed = 0.055
Insert cell
k = 0.062
Insert cell
directNeighborWeight = 0.2
Insert cell
diagonalNeighborWeight = 0.05
Insert cell
function laplace([i, j], val, grid) {
let sum = 0;

const center = grid[i][j];
sum += -1 * center[val];

const directNeighbors = [
[i - 1 < 0 ? colSize - 1 : i - 1, j],
[(i + 1) % colSize, j],
[i, j - 1 < 0 ? colSize - 1 : j - 1],
[i, (j + 1) % colSize]
];
directNeighbors.forEach(
([x, y]) => (sum += directNeighborWeight * grid[x][y][val])
);

const diagonalNeighbors = [
[(i + 1) % colSize, j - 1 < 0 ? colSize - 1 : j - 1],
[(i + 1) % colSize, (j + 1) % colSize],
[i - 1 < 0 ? colSize - 1 : i - 1, (j + 1) % colSize],
[i - 1 < 0 ? colSize - 1 : i - 1, j - 1 < 0 ? colSize - 1 : j - 1]
];
diagonalNeighbors.forEach(
([x, y]) => (sum += diagonalNeighborWeight * grid[x][y][val])
);

return sum;
}
Insert cell
function nextGrid(grid) {
for (let i = 0; i < grid.length; ++i) {
for (let j = 0; j < grid[i].length; ++j) {
const { a, b } = grid[i][j];
grid[i][j] = {
a: a + (d_a * laplace([i, j], 'a', grid) - a * b * b + feed * (1 - a)),
b: b + d_b * laplace([i, j], 'b', grid) + a * b * b - (k + feed) * b
};
}
}
}
Insert cell
function drawGrid(grid, context) {
for (let i = 0; i < grid.length; ++i) {
for (let j = 0; j < grid[i].length; ++j) {
const { a, b } = grid[i][j];
const c = Math.abs(a - b) * 255;
context.fillStyle = `rgba(${c}, ${c}, ${c}, 1)`;
context.fillRect(i * step, j * step, step, step);
}
}
}
Insert cell
Insert cell
function makeGrid() {
const res = [];

for (let x = 0; x < colSize; ++x) {
const row = [];
for (let y = 0; y < colSize; ++y) {
row.push({
a: 0,
b: Math.floor(Math.random() * 2)
});
}
res.push(row);
}

return res;
}
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