💡 Move IFS in special file

This commit is contained in:
Mattéo Delabre 2015-12-23 15:53:50 +01:00
parent b8cef3d9bf
commit e2daa27b9d
1 changed files with 28 additions and 0 deletions

28
scripts/ifs.js Normal file
View File

@ -0,0 +1,28 @@
'use strict';
const linearTransform = (a, b, c, d, e, f) => point => [
a * point[0] + b * point[1] + e,
c * point[0] + d * point[1] + f
];
const polygonTransforms = (vertices, frac) => vertices.map(
vertex => linearTransform(
frac, 0, 0, frac,
vertex[0] * (frac - 1), vertex[1] * (frac - 1)
)
);
export const barnsley = [[
linearTransform(0, 0, 0, 0.16, 0, 0),
linearTransform(.85, .04, -.04, .85, 0, 1.6),
linearTransform(.20, -.26, .23, .22, 0, 1.6),
linearTransform(-.15, .28, .26, .24, 0, .44)
], [
.01, .85, .07, .07
]];
export const sierpinski = [polygonTransforms([
[.866, .5],
[-.866, .5],
[0, -1]
], 1 / 2), [1 / 3, 1 / 3, 1 / 3]];