Fix mouseleave, add debug vector trajectories

This commit is contained in:
Tyler Hallada 2017-08-03 22:59:53 -04:00
parent d32e236e05
commit ec80c5690a

View File

@ -423,12 +423,25 @@ function relativeCounter (counter, targetStart) {
} }
function drawPolygon (polygon, points, counter, tweeningFns) { function drawPolygon (polygon, points, counter, tweeningFns) {
var i, j, easingFn, avgColor, shadedColor, connectionCount, dist, connectivity; var i, j, easingFn, relativeCount, avgColor, shadedColor, connectionCount, dist, connectivity;
// calculate vectors // calculate vectors
for (i = 0; i < points.original.length; i++) { for (i = 0; i < points.original.length; i++) {
easingFn = allTweeningFns[points.target[i][4]]; easingFn = allTweeningFns[points.target[i][4]];
points.tweened[i][0] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][0], points.target[i][0] - points.original[i][0], cycleDuration); relativeCount = relativeCounter(counter, points.target[i][2]);
points.tweened[i][1] = easingFn(relativeCounter(counter, points.target[i][2]), points.original[i][1], points.target[i][1] - points.original[i][1], cycleDuration); points.tweened[i][0] = easingFn(relativeCount, points.original[i][0], points.target[i][0] - points.original[i][0], cycleDuration);
points.tweened[i][1] = easingFn(relativeCount, points.original[i][1], points.target[i][1] - points.original[i][1], cycleDuration);
if (debug) {
// draw vector trajectories
polygon.lineStyle(1, 0x191970, 1);
polygon.moveTo(points.tweened[i][0], points.tweened[i][1]);
for (j = relativeCount; j < cycleDuration; j++) {
polygon.lineTo(
easingFn(j, points.original[i][0], points.target[i][0] - points.original[i][0], cycleDuration),
easingFn(j, points.original[i][1], points.target[i][1] - points.original[i][1], cycleDuration)
);
}
}
} }
// draw lines // draw lines
for (i = 0; i < points.original.length; i++) { for (i = 0; i < points.original.length; i++) {
@ -658,6 +671,12 @@ window.addEventListener('mouseleave', function (e) {
lastHover = null; lastHover = null;
}); });
document.addEventListener('mouseleave', function (e) {
clickEnd = true;
hover = null;
lastHover = null;
});
/* KEYBOARD EVENTS */ /* KEYBOARD EVENTS */
window.addEventListener('keydown', function (e) { window.addEventListener('keydown', function (e) {
@ -691,5 +710,21 @@ window.addEventListener('keydown', function (e) {
fpsEnabled = true; fpsEnabled = true;
lastLoop = new Date(); lastLoop = new Date();
} }
} else if (e.keyCode === 68) {
// toggle debug
if (debug) {
if (fpsEnabled) {
stage.removeChild(fpsGraphic);
}
debug = false;
fpsEnabled = debug;
} else {
if (!fpsEnabled) {
stage.addChild(fpsGraphic);
}
debug = true;
fpsEnabled = debug;
lastLoop = new Date();
}
} }
}); });