💡 Generalize polygon systems

This commit is contained in:
Mattéo Delabre 2015-12-24 12:21:29 +01:00
parent eb689f452f
commit 96b5475447
1 changed files with 18 additions and 5 deletions

View File

@ -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 = [[
linearTransform(0, 0, 0, 0.16, 0, 0),
linearTransform(.85, .04, -.04, .85, 0, 1.6),
@ -21,8 +35,7 @@ export const barnsley = [[
.01, .85, .07, .07
]];
export const sierpinski = [polygonTransforms([
[.866, .5],
[-.866, .5],
[0, -1]
], 1 / 2), [1 / 3, 1 / 3, 1 / 3]];
export const sierpinski = [
polygonTransforms(regularVertices(3), 1 / 2),
[1 / 3, 1 / 3, 1 / 3]
];