Public
Edited
Dec 31, 2023
2 forks
1 star
Also listed in…
Math
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
{
// Note how the 0-1 pattern in the matrix below specifies
// which sub-rectangles are on or off in the image.
let M = [
[0, 1, 1],
[1, 0, 0],
[0, 1, 0],
[0, 1, 1]
];

// The rest should be automatic.
let m = M[0].length;
let n = M.length;
let A = [
[1 / m, 0],
[0, 1 / n]
];
let IFS = [];
for (let i = 1; i <= m; i++) {
for (let j = 1; j <= n; j++) {
if (M[j - 1][i - 1]) {
IFS.push([A, [(i - 1) / m, 1 - j / n]]);
}
}
}
return new IteratedFunctionSystem(IFS).render_stochastic({
n: 60000,
colors: true,
axes: true,
extent: [
[-0.05, 1.05],
[-0.05, 1.05]
],
image_width: width < 900 ? width : 900
});
}
Insert cell
Insert cell
exampleIFS = {
let m = mn.m;
let n = mn.n;
let A = [
[1 / m, 0],
[0, 1 / n]
];
let ifs = [];
let M = 0;
let N = 0;
while (N == 0) {
for (let i = 0; i < m; i++) {
let Mi = 0;
for (let j = 0; j < n; j++) {
if (d3.randomUniform()() < mn.c) {
N = N + 1;
Mi = Mi + 1;
ifs.push([A, [i / m, j / n]]);
}
}
M = M + Math.sign(Mi);
}
}
mn.M = M;
mn.N = N;
return new IteratedFunctionSystem(ifs);
}
Insert cell
mn = {
redo;
let c = d3.randomUniform(0.1, 1)();
let m = d3.randomInt(2, 5)();
let n = d3.randomInt(m + 1, 7)();
return { c: c, m: m, n: n };
}
Insert cell
import { IteratedFunctionSystem } 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