Published
Edited
Nov 13, 2019
Insert cell
Insert cell
now.t
Insert cell
Insert cell
now = {
let now = points,
t = 0,
minWidth = Infinity
while (true) {
now = step(now)
t++

const extent = d3.extent(now, p => p.p[0]),
width = extent[1] - extent[0]
if (width > minWidth)
break

minWidth = width
if (width < 500)
yield { t, points: now }
}
}
Insert cell
function step(points) {
return points.map(p => ({ p: [p.p[0] + p.v[0], p.p[1] + p.v[1]], v: p.v }))
}
Insert cell
points = lines
.map(l => l.match(/position=<\s*(-?\d+),\s*(-?\d+)> velocity=<\s*(-?\d+),\s*(-?\d+)>/).slice(1).map(Number))
.map(p => ({ p: [p[0], p[1]], v: [p[2], p[3]] }))
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