-
Notifications
You must be signed in to change notification settings - Fork 4
Add homepage confetti effect for 50th Remote Hack celebration #216
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
hack_number: 50 | ||
date: 2024-06-29 | ||
upcoming: true | ||
celebrate: true | ||
--- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Confetti effect implementation | ||
(function() { | ||
// Check for prefers-reduced-motion | ||
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; | ||
if (prefersReducedMotion) { | ||
return; | ||
} | ||
|
||
const canvas = document.createElement('canvas'); | ||
const ctx = canvas.getContext('2d'); | ||
document.body.appendChild(canvas); | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
|
||
const confettis = []; | ||
const colors = ['#FFC0CB', '#FFD700', '#8A2BE2', '#00FF00', '#FF4500', '#00BFFF']; | ||
|
||
function createConfetti() { | ||
const x = Math.floor(Math.random() * canvas.width); | ||
const y = Math.floor(Math.random() * canvas.height); | ||
const color = colors[Math.floor(Math.random() * colors.length)]; | ||
const size = Math.random() * (15 - 5) + 5; | ||
const speed = Math.random() * (5 - 2) + 2; | ||
const angle = Math.random() * 360; | ||
confettis.push({x, y, color, size, speed, angle}); | ||
} | ||
|
||
function drawConfetti() { | ||
confettis.forEach((confetti, index) => { | ||
ctx.beginPath(); | ||
ctx.arc(confetti.x, confetti.y, confetti.size, 0, 2 * Math.PI); | ||
ctx.fillStyle = confetti.color; | ||
ctx.fill(); | ||
|
||
// Update confetti position | ||
confetti.y += confetti.speed; | ||
confetti.x += Math.cos(confetti.angle) * confetti.speed; | ||
|
||
// Remove confetti that are out of the screen | ||
if (confetti.y > canvas.height) { | ||
confettis.splice(index, 1); | ||
} | ||
}); | ||
} | ||
|
||
function update() { | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
drawConfetti(); | ||
requestAnimationFrame(update); | ||
} | ||
|
||
// Create confettis every 100ms | ||
setInterval(createConfetti, 100); | ||
|
||
// Stop creating confettis after 5 seconds | ||
setTimeout(() => { | ||
clearInterval(createConfetti); | ||
Comment on lines
+53
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no interval id being stored, so it'll never stop 🤔 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you can limit it easily to just the homepage then I think this is fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep I guess it is fine! I thought it was worth noting that the code from Copilot Workspace Preview has syntax issues 😓 |
||
}, 5000); | ||
|
||
update(); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't do this, it is basically just a memory leak?