Published
Edited
Apr 28, 2019
26 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
points = {
// Define an x range of 0-1, which we will scale later on.
// For demonstration purposes y will store the current iteration.
return splitLine(0, 0, 1, 0, iterations, getMidPoint).reduce(reducePoints, []);
function getMidPoint(x1, y1, x2, y2) {
const t = .5 * (1 - randomness) + Math.random() * randomness;
// Split at an (optional random) x offset.
const x = x1 * (1- t) + x2 * t;
// Use the y offset to store the iteration index.
const y = Math.max(y1, y2) + 1;
return [x, y];
}
// Combines a list of offsets to arrays of [x, y].
function reducePoints(arr, v, i, points) {
if(i % 2) arr.push([points[i - 1], v]);
return arr;
}
}
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