Public
Edited
Nov 28, 2022
2 forks
2 stars
Also listed in…
Math
Fractals
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
p = (1 + Math.sqrt(5)) / 2
Insert cell
full_digraph_input = [
{
// Rectangle in rectangle
source: "R",
target: "R",
f: shift([p, 0])
.compose(rotate(pi / 2))
.compose(scale(1 / p)),
label: "RR"
},
{
// Square in rectangle - don't delete!!
source: "R",
target: "S",
f: scale(1),
label: "RS"
},
{
// Lower left rectangle in square
source: "S",
target: "R",
f: scale(1 / p ** 2),
label: "SR1"
},
{
// Lower right rectangle in square
source: "S",
target: "R",
f: shift([1 / p + 1 / p ** 2, 0])
.compose(scale(1 / p ** 2))
.compose(rotate(pi / 2)),
label: "SR2"
},
{
// Upper left rectangle in square
source: "S",
target: "R",
f: shift([1 / p ** 2, 1 / p ** 2])
.compose(scale(1 / p ** 2))
.compose(rotate(pi / 2)),
label: "SR3"
},
{
// Upper right rectangle in square
source: "S",
target: "R",
f: shift([1 / p ** 2, 1 / p]).compose(scale(1 / p ** 2)),
label: "SR4"
},
{
// Square in square
source: "S",
target: "S",
f: shift([1 / p ** 2, 1 / p ** 2]).compose(scale(1 / p ** 3)),
label: "SS"
}
]
Insert cell
Insert cell
full_digraphIFS = new DigraphIFS(full_digraph_input)
Insert cell
Insert cell
smaller_digraph_input = [
{
// Rectangle in rectangle
source: "R",
target: "R",
f: shift([p, 0])
.compose(rotate(pi / 2))
.compose(scale(1 / p)),
label: "RR"
},
{
// Square in rectangle - don't delete!!
source: "R",
target: "S",
f: scale(1),
label: "RS"
},
{
// Lower left rectangle in square
source: "S",
target: "R",
f: scale(1 / p ** 2),
label: "SR1"
},
{
// Lower right rectangle in square
source: "S",
target: "R",
f: shift([1 / p + 1 / p ** 2, 0])
.compose(scale(1 / p ** 2))
.compose(rotate(pi / 2)),
label: "SR2"
},
{
// Upper left rectangle in square
source: "S",
target: "R",
f: shift([1 / p ** 2, 1 / p ** 2])
.compose(scale(1 / p ** 2))
.compose(rotate(pi / 2)),
label: "SR3"
},
{
// Upper right rectangle in square
source: "S",
target: "R",
f: shift([1 / p ** 2, 1 / p]).compose(scale(1 / p ** 2)),
label: "SR4"
}
// {
// // Square in square
// source: "S",
// target: "S",
// f: shift([1 / p ** 2, 1 / p ** 2]).compose(scale(1 / p ** 3)),
// label: "SS"
// }
]
Insert cell
Insert cell
digraphIFS = new DigraphIFS(smaller_digraph_input)
Insert cell
Insert cell
digraphIFS.show_digraph()
Insert cell
Insert cell
pics = digraphIFS.render_stochastic({ n: 100000, colors: true })
Insert cell
Insert cell
pics[2]
Insert cell
Insert cell
Insert cell
## Ancillary code
Insert cell
// Good initiators for the deterministic method
init = [
[
[0, 0],
[p, 0],
[p, 1],
[0, 1],
[0, 0]
],
[
[0, 0],
[1, 0],
[1, 1],
[0, 1],
[0, 0]
]
]
Insert cell
import {
scale,
shift,
rotate,
reflect,
pi,
DigraphIFS
} from "@mcmcclur/digraphifs-class"
Insert cell
MathJax = require("https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js").catch(
() => window["MathJax"]
)
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