From e2daa27b9d4159de950cca9c6ff9811c9730cb45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 23 Dec 2015 15:53:50 +0100 Subject: [PATCH] :bulb: Move IFS in special file --- scripts/ifs.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 scripts/ifs.js 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]];