From e88f70a0b5d3b2aba9e137ac762bbcd6b7b87f69 Mon Sep 17 00:00:00 2001 From: Inanc Date: Sun, 3 Apr 2022 01:51:07 +0300 Subject: [PATCH 1/3] pause and continue functions added --- src/confetti.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/confetti.js b/src/confetti.js index 21d95f7..966867e 100644 --- a/src/confetti.js +++ b/src/confetti.js @@ -180,13 +180,25 @@ export default function ConfettiGenerator(params) { clearInterval(appstate.interval); requestAnimationFrame(function() { - ctx.clearRect(0, 0, cv.width, cv.height); + ctx.clearRect(0, 0, cv.width, cv.height); var w = cv.width; cv.width = 1; cv.width = w; }); } + ////////////// + // Pause confetti animation + var _pause = function () { + appstate.animate = "paused"; + } + + ////////////// + // Continue confetti animation + var _continue = function () { + appstate.animate = true; + } + ////////////// // Render confetti on canvas var _render = function() { @@ -214,8 +226,9 @@ export default function ConfettiGenerator(params) { var p = particles[i]; if (p) { - if(appstate.animate) - p.y += p.speed; + if((typeof appstate.animate === "boolean" && appstate.animate)) { + p.y += p.speed + } if (p.rotate) p.rotation += p.speed / 35; @@ -242,6 +255,8 @@ export default function ConfettiGenerator(params) { return { render: _render, - clear: _clear + clear: _clear, + pause: _pause, + continue: _continue } -} +} \ No newline at end of file From 32cf54718ecf819c88cbf16fef9fa7871743b7d6 Mon Sep 17 00:00:00 2001 From: Inanc Date: Sun, 3 Apr 2022 02:01:57 +0300 Subject: [PATCH 2/3] commented lines removed --- src/confetti.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/confetti.js b/src/confetti.js index 966867e..a274006 100644 --- a/src/confetti.js +++ b/src/confetti.js @@ -187,13 +187,11 @@ export default function ConfettiGenerator(params) { }); } - ////////////// // Pause confetti animation var _pause = function () { appstate.animate = "paused"; } - ////////////// // Continue confetti animation var _continue = function () { appstate.animate = true; @@ -221,14 +219,13 @@ export default function ConfettiGenerator(params) { } function update() { - for (var i = 0; i < appstate.max; i++) { var p = particles[i]; if (p) { if((typeof appstate.animate === "boolean" && appstate.animate)) { p.y += p.speed - } + } if (p.rotate) p.rotation += p.speed / 35; From 65edf22b969d4ad5e2ad296713935a4980818c0c Mon Sep 17 00:00:00 2001 From: Inanc Date: Sun, 3 Apr 2022 02:27:45 +0300 Subject: [PATCH 3/3] rotate paused too when animate is paused --- src/confetti.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/confetti.js b/src/confetti.js index a274006..ae229aa 100644 --- a/src/confetti.js +++ b/src/confetti.js @@ -227,8 +227,9 @@ export default function ConfettiGenerator(params) { p.y += p.speed } - if (p.rotate) + if ((typeof appstate.animate === "boolean" && appstate.animate) && p.rotate) { p.rotation += p.speed / 35; + } if ((p.speed >= 0 && p.y > appstate.height) || (p.speed < 0 && p.y < 0)) { if(appstate.respawn) {