diff --git a/scripts/ifs.js b/scripts/ifs.js new file mode 100644 index 0000000..df58ae2 --- /dev/null +++ b/scripts/ifs.js @@ -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]];