From 6b6997511ef29f1eb0616e91372e8b46ba4bdece Mon Sep 17 00:00:00 2001 From: Tyler Hallada Date: Sun, 13 Aug 2017 01:15:24 -0400 Subject: [PATCH] Implement reset button --- js/proximity.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/js/proximity.js b/js/proximity.js index 3eb1ebd..5fb1903 100644 --- a/js/proximity.js +++ b/js/proximity.js @@ -28,6 +28,7 @@ var hover = null; var lastHover = null; var clickEnd = false; var sprites = []; +var reset = false; // global configurable vars var resolution = 1; // scaling for PIXI renderer @@ -472,10 +473,12 @@ function getRandomPoints (numPoints, maxX, maxY, maxZ, tweeningFns) { cycleStart = randomInt(0, cycleDuration - 1); color = randomColor(); easingFn = tweeningFns[Math.floor(Math.random() * tweeningFns.length)]; - // save PIXI Sprite for each point in array - sprite = createSprite(); - sprites.push(sprite); - stage.addChild(sprite); + if (sprites.length <= i) { + // save PIXI Sprite for each point in array + sprite = createSprite(); + sprites.push(sprite); + stage.addChild(sprite); + } points[i] = [x, y, z, cycleStart, color, easingFn]; } return points; @@ -668,6 +671,18 @@ function loop () { polygon.clear(); + if (reset === true) { + var newPoints; + newPoints = getRandomPoints(Math.round(totalScreenPixels / 6), screenWidth, screenHeight, zRange, + tweeningFns); + polygonPoints = { + original: newPoints, + target: JSON.parse(JSON.stringify(newPoints)), + tweened: JSON.parse(JSON.stringify(newPoints)) + }; + reset = false; + } + if (click !== null) { if (clickEnd) { // apply "rebound" effects @@ -964,12 +979,14 @@ window.onload = function () { document.getElementById('synchronize-cycles').addEventListener('click', function () { synchronizeCycles(polygonPoints, cycleDuration); - return false; }, false); document.getElementById('randomize-cycles').addEventListener('click', function () { randomizeCycles(polygonPoints, cycleDuration); - return false; + }, false); + + document.getElementById('reset').addEventListener('click', function () { + reset = true; }, false); var timeRange, timeInput;