💡 Generalize polygon systems
This commit is contained in:
parent
eb689f452f
commit
96b5475447
|
@ -12,6 +12,20 @@ const polygonTransforms = (vertices, frac) => vertices.map(
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const regularVertices = count => {
|
||||||
|
var step = 2 * Math.PI / count;
|
||||||
|
var initial = -Math.atan(Math.sin(step) / (Math.cos(step) - 1));
|
||||||
|
var result = [];
|
||||||
|
|
||||||
|
for (var i = 0; i < count; i += 1) {
|
||||||
|
var current = step * i + initial;
|
||||||
|
|
||||||
|
result.push([Math.cos(current) * 10, Math.sin(current) * 10]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
export const barnsley = [[
|
export const barnsley = [[
|
||||||
linearTransform(0, 0, 0, 0.16, 0, 0),
|
linearTransform(0, 0, 0, 0.16, 0, 0),
|
||||||
linearTransform(.85, .04, -.04, .85, 0, 1.6),
|
linearTransform(.85, .04, -.04, .85, 0, 1.6),
|
||||||
|
@ -21,8 +35,7 @@ export const barnsley = [[
|
||||||
.01, .85, .07, .07
|
.01, .85, .07, .07
|
||||||
]];
|
]];
|
||||||
|
|
||||||
export const sierpinski = [polygonTransforms([
|
export const sierpinski = [
|
||||||
[.866, .5],
|
polygonTransforms(regularVertices(3), 1 / 2),
|
||||||
[-.866, .5],
|
[1 / 3, 1 / 3, 1 / 3]
|
||||||
[0, -1]
|
];
|
||||||
], 1 / 2), [1 / 3, 1 / 3, 1 / 3]];
|
|
||||||
|
|
Loading…
Reference in New Issue