Published
Edited
Dec 10, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// Used for just the level zero display
T0 = {
let T = [
[
[
[0, 0],
[1, 0],
[1, 1],
[0, 1]
]
]
];
let n = 9;
for (let i = 0; i < n; i++) {
T = multi_polygon_step(T, i);
}
let An = math.pow(math.inv(A), n);
let S = [
[1, -1 / 2],
[0, Math.sqrt(3) / 2]
];
T = T.map((p) => p.map((pts) => pts.map((xy) => math.multiply(S, An, xy))));
return T;
}
Insert cell
// Used for higher order displays
T = {
let T = [
[
[
[0, 0],
[1, 0],
[1, 1],
[0, 1]
]
]
];
let n = 6;
for (let i = 0; i < n; i++) {
T = multi_polygon_step(T, i);
}
let An = math.pow(math.inv(A), n);
let S = [
[1, -1 / 2],
[0, Math.sqrt(3) / 2]
];
T = T.map((p) => p.map((pts) => pts.map((xy) => math.multiply(S, An, xy))));
return T;
}
Insert cell
Insert cell
// A polygon looks like [pts_0, pts_1, ...]
// where pts_0 is a list of points describing an outer ring
// and each pts_i are optional further lists that describe holes
// in the outer ring

// This function accepts polygons and applies the IFS

function polygon_step(p, n) {
let An = math.pow(A, n);
return D.map(function (d) {
return p.map((a) => a.map((aa) => math.add(math.multiply(An, d), aa)));
});
}
Insert cell
// A multi-polygon is a list of polygons. This function accepts a multipolygon,
// applies the IFS to each polygon in that multipolygon, and merges the result
// by applying polygonClipping.union.

function multi_polygon_step(mp, n) {
return polygonClipping.union(...mp.map((p) => polygon_step(p, n)));
}
Insert cell
Insert cell
IFS = {
let AInv = math.inv(A);
let B = [
[1, -1 / 2],
[0, Math.sqrt(3) / 2]
];
AInv = math.multiply(B, AInv, math.inv(B));
let IFS = new IteratedFunctionSystem(
D.map((d) => new AffineFunction([AInv, math.multiply(AInv, B, d)]))
);
return IFS;
}
Insert cell
D = base_digit_set(A)
Insert cell
A = [
[2, -1],
[1, 1]
]
Insert cell
Insert cell
import {
viewof depth,
tile_development,
base_digit_set,
IteratedFunctionSystem,
AffineFunction
} from "@mcmcclur/self-affine-tiles"
Insert cell
math = require("mathjs")
Insert cell
polygonClipping = require("polygon-clipping")
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