Confetti for the winners #37

Merged
guggerud merged 3 commits from feat/confetti into master 2020-09-11 07:47:50 +00:00
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";
}
KevinMidboe commented 2020-09-10 12:19:41 +00:00 (Migrated from github.com)
Review

This is pretty similar to the function above. Can some of the code be separated into a more general function and instead send defaults or confetti objects down to the more general function?

This is pretty similar to the function above. Can some of the code be separated into a more general function and instead send `defaults` or confetti objects down to the more general function?
guggerud commented 2020-09-10 12:25:44 +00:00 (Migrated from github.com)
Review

I should indeed be able to reduce redundancy here!

I should indeed be able to reduce redundancy here!
guggerud commented 2020-09-10 14:51:39 +00:00 (Migrated from github.com)
Review

fixed

fixed
}
},
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 }))
}
},
}
};
KevinMidboe commented 2020-09-10 12:17:36 +00:00 (Migrated from github.com)
Review

Nice with a comment that explains the size in seconds here.

Nice with a comment that explains the size in seconds here.
guggerud commented 2020-09-10 12:23:07 +00:00 (Migrated from github.com)
Review

I will include a comment to be more descriptive, thanks!

I will include a comment to be more descriptive, thanks!
guggerud commented 2020-09-10 14:51:32 +00:00 (Migrated from github.com)
Review

Fixed

Fixed
</script>
<style lang="scss" scoped>