Public
Edited
Jun 16, 2022
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
initialPoints = new Array(polygonSides).fill().map((_, i, a) => [
Math.cos(TAU * i / a.length + theta),
Math.sin(TAU * i / a.length + theta)
])
Insert cell
points = {
randomize

const points = [...initialPoints]

// Seed with an initial random, non-vertex, point, if initial point random is set
if (initialPoint === 'Random') points.push([d3.randomUniform(-1, 1)(), d3.randomUniform(-1, 1)()])
let lastPoint
while (points.length < pointCount) {
points.push(
simpleGenerator(
points[points.length - 1],
jumpRatio,
initialPoints
)
)
}
return points
}
Insert cell
Insert cell
simpleGenerator = (lastPoint, jumpRatio, vertices) => {
// Pick a vertex
const randVertexIdx = d3.randomInt(0, vertices.length)()
const randVertex = vertices[randVertexIdx]
// Create a new point that is jumpRatio between the two
return [
(lastPoint[0] - randVertex[0]) * jumpRatio + randVertex[0],
(lastPoint[1] - randVertex[1]) * jumpRatio + randVertex[1],
]
}
Insert cell
Insert cell
TAU = Math.PI * 2
Insert cell
WIDTH = Math.min(width, 800)
Insert cell
HEIGHT = WIDTH
Insert cell
PADDING = WIDTH * 0.1
Insert cell
Insert cell
project = ([x, y]) => {
const innerWidth = WIDTH - PADDING * 2
const innerHeight = innerWidth
return [
(x + 1) / 2 * innerWidth + PADDING,
(y + 1) / 2 * innerWidth + PADDING,
]
}
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