Merge pull request #37 from KevinMidboe/feat/confetti

Confetti for the winners
This commit is contained in:
2020-09-11 09:47:49 +02:00
committed by GitHub
3 changed files with 40 additions and 1 deletions

5
package-lock.json generated
View File

@@ -2334,6 +2334,11 @@
"integrity": "sha512-zQW8V3CdND7GHRH6rxm6s59Ww4g/qGWTheoboW9nfeMg7sUoopIfKCcNZUjwYRCOrvereh3kwDpZj4VLQ7zGtA==",
"dev": true
},
"canvas-confetti": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/canvas-confetti/-/canvas-confetti-1.2.0.tgz",
"integrity": "sha512-0B49O9CfLciAYz4hriu9pvWNGkCtVcpvyNFKWZI+JVWJM5nJTMg5MX3cFzatyeYcOL6bR1Jw3yhZKbgt03O8/Q=="
},
"caseless": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",

View File

@@ -15,6 +15,7 @@
"@babel/polyfill": "~7.2",
"@zxing/library": "^0.15.2",
"body-parser": "^1.19.0",
"canvas-confetti": "^1.2.0",
"chart.js": "^2.9.3",
"clean-webpack-plugin": "^3.0.0",
"compression": "^1.7.4",

View File

@@ -15,6 +15,7 @@
<br />
<br />
</div>
<div class="current-draw" v-if="drawingDone">
<h2>VINNER</h2>
<div
@@ -34,6 +35,7 @@
</template>
<script>
import confetti from "canvas-confetti";
export default {
props: {
currentWinner: {
@@ -99,6 +101,7 @@ export default {
}
this.drawing = false;
this.drawingDone = true;
this.startConfetti(this.currentName);
return;
}
this.currentName = this.attendees[
@@ -147,9 +150,39 @@ export default {
case 3:
return "yellow";
}
}
},
startConfetti(currentName){
//duration is computed as x * 1000 miliseconds, in this case 7*1000 = 7000 miliseconds ==> 7 seconds.
var duration = 7 * 1000;
var animationEnd = Date.now() + duration;
var defaults = { startVelocity: 30, spread: 360, ticks: 60, zIndex: 0, particleCount: 10};
var uberDefaults = { startVelocity: 65, spread: 75, particleCount: 35, angle: randomInRange(55, 125)}
function randomInRange(min, max) {
return Math.random() * (max - min) + min;
}
var interval = setInterval(function() {
var timeLeft = animationEnd - Date.now();
if (timeLeft <= 0) {
return clearInterval(interval);
}
if(currentName == "Amund Brandsrud"){
runCannon(uberDefaults, {x: 0 });
runCannon(uberDefaults, {x: 1 });
runCannon(uberDefaults, {y: 1 });
}else{
runCannon(defaults, { x: randomInRange(0.1, 0.3), y: Math.random() - 0.2 });
runCannon(defaults, { x: randomInRange(0.7, 0.9), y: Math.random() - 0.2 });
}
}, 250);
function runCannon(confettiDefaultValues, originPoint){
confetti(Object.assign({}, confettiDefaultValues, {origin: originPoint }))
}
},
}
};
</script>
<style lang="scss" scoped>