Published
Edited
Oct 17, 2021
1 star
Insert cell
Insert cell
Insert cell
{
replot;
let vertices = d3
.range(3)
.map(() => [d3.randomUniform()(), d3.randomUniform()()]);
let IFS = new IteratedFunctionSystem(vertices.map((vv) => scale(1 / 2, vv)));
let canvas = IFS.render_stochastic({ colors: true });

let context = canvas.getContext("2d");
let xScale = IFS.xScale;
let yScale = IFS.yScale;

vertices.forEach(add_vertex);

function add_vertex(v, i) {
context.fillStyle = "white";
context.lineWidth = 2;
context.strokeStyle = d3.schemeCategory10[i];
context.beginPath();
context.arc(xScale(v[0]), yScale(v[1]), 4, 0, 2 * Math.PI);
context.fill();
context.stroke();
}

return canvas;
}
Insert cell
import {
IteratedFunctionSystem,
scale
} from "@mcmcclur/iterated-function-systems"
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