Published
Edited
Jan 4, 2020
Insert cell
md`# Barnsley Fern: Thelypteridaceae`
Insert cell
paper = require("paper");
Insert cell
{
// Drawing technical details.
let canvas = this || DOM.canvas(500, 400);
let ps = canvas.ps || (() => {
let ps = new paper.PaperScope();
ps.setup(canvas);
return ps;
})();
canvas.ps = ps;
const iterations = 10000;
const scale = 50;
let start = new ps.Point(250, 365);
let i = 0;
let turtle = [0., 0.];
while (i++ < iterations) {
turtle = simplex.transformation.forward(turtle)
let point = new paper.Point(
start.x + turtle[0] * 1 * scale, start.y - turtle[1] * scale);
let circle = new ps.Path.Circle(point, 0.05);
circle.strokeColor = "black";
};
return canvas;
}
Insert cell
Insert cell
Insert cell
class Simplex {
constructor(probs, events) {
this.probs = probs;
this.events = events;
}
get transformation() {
let r = Math.random();
let total = 0;
for (let i in this.probs) {
total += this.probs[i];
if (r <= total) {
return this.events[i];
}
}
throw Error("Impossible!");
}
}
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