Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pause and continue functions added #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions src/confetti.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,23 @@ 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() {
Expand All @@ -209,16 +219,17 @@ export default function ConfettiGenerator(params) {
}

function update() {

for (var i = 0; i < appstate.max; i++) {
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)
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) {
Expand All @@ -242,6 +253,8 @@ export default function ConfettiGenerator(params) {

return {
render: _render,
clear: _clear
clear: _clear,
pause: _pause,
continue: _continue
}
}
}