Published
Edited
Apr 21, 2021
Fork of Random walks
1 fork
Insert cell
md`# Random walks p2`
Insert cell
chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, 800, 800]);
for (var j=0; j < 3; j++) {
let x=400,y=400,length=10;
let color = ["red", "yellow", "blue"][j];
svg.append("circle").attr("cx", x).attr("cy", y).attr("r", length * 0.75).attr("stroke", color).attr("fill", "none");

for (var i=0; i < Math.ceil(100000 * Math.random()); i++) {

let vord = Math.random() < 0.5,
dist = length * (Math.random() < 0.5 ? 1 : -1),
xp = vord ? x + dist : x,
yp = vord ? y : y + dist;
svg.append("line").attr("x1", x).attr("y1", y).attr("x2", xp).attr("y2", yp).attr("stroke", color);
x = xp;
y = yp;

}
svg.append("circle").attr("cx", x).attr("cy", y).attr("r", length * 0.75).attr("stroke", color).attr("fill", "none");

}
return svg.node();
}
Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell
d3 = require("d3@6")
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