Implement reset button

This commit is contained in:
Tyler Hallada 2017-08-13 01:15:24 -04:00
parent 94b6fdead2
commit 6b6997511e

View File

@ -28,6 +28,7 @@ var hover = null;
var lastHover = null; var lastHover = null;
var clickEnd = false; var clickEnd = false;
var sprites = []; var sprites = [];
var reset = false;
// global configurable vars // global configurable vars
var resolution = 1; // scaling for PIXI renderer var resolution = 1; // scaling for PIXI renderer
@ -472,10 +473,12 @@ function getRandomPoints (numPoints, maxX, maxY, maxZ, tweeningFns) {
cycleStart = randomInt(0, cycleDuration - 1); cycleStart = randomInt(0, cycleDuration - 1);
color = randomColor(); color = randomColor();
easingFn = tweeningFns[Math.floor(Math.random() * tweeningFns.length)]; easingFn = tweeningFns[Math.floor(Math.random() * tweeningFns.length)];
if (sprites.length <= i) {
// save PIXI Sprite for each point in array // save PIXI Sprite for each point in array
sprite = createSprite(); sprite = createSprite();
sprites.push(sprite); sprites.push(sprite);
stage.addChild(sprite); stage.addChild(sprite);
}
points[i] = [x, y, z, cycleStart, color, easingFn]; points[i] = [x, y, z, cycleStart, color, easingFn];
} }
return points; return points;
@ -668,6 +671,18 @@ function loop () {
polygon.clear(); 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 (click !== null) {
if (clickEnd) { if (clickEnd) {
// apply "rebound" effects // apply "rebound" effects
@ -964,12 +979,14 @@ window.onload = function () {
document.getElementById('synchronize-cycles').addEventListener('click', function () { document.getElementById('synchronize-cycles').addEventListener('click', function () {
synchronizeCycles(polygonPoints, cycleDuration); synchronizeCycles(polygonPoints, cycleDuration);
return false;
}, false); }, false);
document.getElementById('randomize-cycles').addEventListener('click', function () { document.getElementById('randomize-cycles').addEventListener('click', function () {
randomizeCycles(polygonPoints, cycleDuration); randomizeCycles(polygonPoints, cycleDuration);
return false; }, false);
document.getElementById('reset').addEventListener('click', function () {
reset = true;
}, false); }, false);
var timeRange, timeInput; var timeRange, timeInput;