Public
Edited
Nov 8, 2020
1 fork
7 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
idwAlgo = function(gens, nb) {
let sw = 0; // sum of all weights
let sn = 0; // sum of all weighted heights
const { x, y } = this.thread;

for (let k = 0; k < nb; k++) {
const [gx, gy] = gens[k];
const [dx, dy] = [x - gx, y - gy];
const dist2 = dx * dx + dy * dy;
sn += k / dist2; // k/nb = influence of generator k
sw += nb / dist2;
}

return sn / sw;
}
Insert cell
cropAlgo = function(array2D, range) {
const { x, y } = this.thread;
const [min, max] = range;
const h = array2D[y][x];
return Math.min(max, Math.max(min, h));
}
Insert cell
computeHeightmap = {
const idwKernel = gpu.createKernel(idwAlgo, { output });
const cropKernel = gpu.createKernel(cropAlgo, { output });
const combine = function(gens, nb, range) {
return cropKernel(idwKernel(gens, nb), range);
};
return gpu.combineKernels(idwKernel, cropKernel, combine);
}
Insert cell
viewof height = {
const heightmap = computeHeightmap(generators, generators.length, crop);
const canvas = (render(heightmap), render.canvas);
return Object.assign(canvas, { value: heightmap });
}
Insert cell
height
Insert cell
Insert cell
Insert cell
Insert cell
shade
Insert cell
Insert cell
Insert cell
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