From b8cef3d9bfec8b40fcfe0ba6f07afc24a14c3ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Wed, 23 Dec 2015 15:53:33 +0100 Subject: [PATCH] :bulb: Factor rendering logic out of chaos.js --- scripts/chaos.js | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/scripts/chaos.js b/scripts/chaos.js index 6887197..f19f85d 100644 --- a/scripts/chaos.js +++ b/scripts/chaos.js @@ -1,7 +1,5 @@ 'use strict'; -import { getColor } from './utils'; - /** * Choose an index at random among a list of weights, * more weighted indices have a greater proability to be chosen @@ -33,8 +31,7 @@ const chooseIndex = weights => { * @param {Array} weights Probability weights for each transform * @return {null} */ -export const applyChaos = (image, start, iterations, transforms, weights) => { - const width = image.width; +export const applyChaos = (image, start, iterations, transforms, weights, cb) => { let point = start; if (weights === undefined) { @@ -45,20 +42,8 @@ export const applyChaos = (image, start, iterations, transforms, weights) => { while (iterations--) { const index = chooseIndex(weights); - const color = getColor(2); - - // console.log(point); - // console.log(point.map(x => Math.floor(x * 10 + 100))); point = transforms[index](point); - const i = ( - Math.floor(point[1] * 50 + 50) * width + - Math.floor(point[0] * 50 + 200) - ) * 4; - - image.data[i] = color[0]; - image.data[i + 1] = color[1]; - image.data[i + 2] = color[2]; - image.data[i + 3] = 255; + cb(point); } };