var canvas1, ctx, w, h; if (screen.width >= 988) var mp = 150; else mp = 75; var deactivationtimerhandler, reactivationtimerhandler, animationhandler, particles = [], angle = 0, tiltangle = 0, confettiactive = !0, animationcomplete = !0, particlecolors = { coloroptions: [ "dodgerblue", "olivedrab", "gold", "pink", "slateblue", "lightblue", "violet", "palegreen", "steelblue", "sandybrown", "chocolate", "crimson", ], colorindex: 0, colorincrementer: 0, colorthreshold: 10, getcolor: function () { return ( this.colorincrementer >= 10 && ((this.colorincrementer = 0), this.colorindex++, this.colorindex >= this.coloroptions.length && (this.colorindex = 0)), this.colorincrementer++, this.coloroptions[this.colorindex] ); }, }; function confettiparticle(t) { (this.x = math.random() * w), (this.y = math.random() * h - h), (this.r = randomfromto(10, 30)), (this.d = math.random() * mp + 10), (this.color = t), (this.tilt = math.floor(10 * math.random()) - 10), (this.tiltangleincremental = 0.07 * math.random() + 0.05), (this.tiltangle = 0), (this.draw = function () { return ( ctx.beginpath(), (ctx.linewidth = this.r / 2), (ctx.strokestyle = this.color), ctx.moveto(this.x + this.tilt + this.r / 4, this.y), ctx.lineto(this.x + this.tilt, this.y + this.tilt + this.r / 4), ctx.stroke() ); }); } function initializebutton() { $("#stopbutton").click(deactivateconfetti), $("#startbutton").click(restartconfetti); } function setglobals() { (canvas1 = document.getelementbyid("canvas")), (ctx = canvas1.getcontext("2d")), (w = window.innerwidth), (h = window.innerheight), (canvas1.width = w), (canvas1.height = h); } function initializeconfetti() { (particles = []), (animationcomplete = !1); for (var t = 0; t < mp; t++) { var i = particlecolors.getcolor(); particles.push(new confettiparticle(i)); } startconfetti(); } function draw() { ctx.clearrect(0, 0, w, h); for (var t, i = [], n = 0; n < mp; n++) (t = n), i.push(particles[t].draw()); return update(), i; } function randomfromto(t, i) { return math.floor(math.random() * (i - t + 1) + t); } function update() { var t, i = 0; (angle += 0.01), (tiltangle += 0.1); for (var n = 0; n < mp; n++) { if (((t = particles[n]), animationcomplete)) return; !confettiactive && t.y < -15 ? (t.y = h + 100) : (stepparticle(t, n), t.y <= h && i++, checkforreposition(t, n)); } 0 === i && stopconfetti(); } function checkforreposition(t, i) { (t.x > w + 20 || t.x < -20 || t.y > h) && confettiactive && (i % 5 > 0 || i % 2 == 0 ? repositionparticle( t, math.random() * w, -10, math.floor(10 * math.random()) - 10 ) : math.sin(angle) > 0 ? repositionparticle( t, -5, math.random() * h, math.floor(10 * math.random()) - 10 ) : repositionparticle( t, w + 5, math.random() * h, math.floor(10 * math.random()) - 10 )); } function stepparticle(t, i) { (t.tiltangle += t.tiltangleincremental), (t.y += (math.cos(angle + t.d) + 3 + t.r / 2) / 2), (t.x += math.sin(angle)), (t.tilt = 15 * math.sin(t.tiltangle - i / 3)); } function repositionparticle(t, i, n, e) { // (t.x = i), (t.y = n), (t.tilt = e); } function startconfetti() { (w = window.innerwidth), (h = window.innerheight), (canvas1.width = w), (canvas1.height = h), (function t() { return animationcomplete ? null : ((animationhandler = requestanimframe(t)), draw()); })(); } function cleartimers() { cleartimeout(reactivationtimerhandler), cleartimeout(animationhandler); } function deactivateconfetti() { (confettiactive = !1), cleartimers(); } function stopconfetti() { (animationcomplete = !0), null != ctx && ctx.clearrect(0, 0, w, h); } function restartconfetti() { cleartimers(), stopconfetti(), (reactivationtimerhandler = settimeout(function () { (confettiactive = !0), (animationcomplete = !1), initializeconfetti(); }, 100)); } $(document).ready(function () { setglobals(), initializebutton(), initializeconfetti(), $(window).resize(function () { (w = window.innerwidth), (h = window.innerheight), (canvas1.width = w), (canvas1.height = h); }); }), (window.requestanimframe = window.requestanimationframe || window.webkitrequestanimationframe || window.mozrequestanimationframe || window.orequestanimationframe || window.msrequestanimationframe || function (t) { return window.settimeout(t, 1e3 / 60); });