-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package friends | ||
|
||
import ( | ||
"embed" | ||
|
||
"github.com/movsb/taoblog/modules/utils" | ||
"github.com/movsb/taoblog/modules/utils/dir" | ||
dynamic "github.com/movsb/taoblog/service/modules/renderers/_dynamic" | ||
"github.com/movsb/taoblog/theme/modules/sass" | ||
) | ||
|
||
//go:generate sass --no-source-map style.scss style.css | ||
|
||
//go:embed style.css script.js | ||
var _root embed.FS | ||
|
||
func init() { | ||
dynamic.RegisterInit(func() { | ||
dynamic.Dynamic[`anniversary`] = dynamic.Content{ | ||
Styles: []string{ | ||
string(utils.Must1(_root.ReadFile(`style.css`))), | ||
}, | ||
Scripts: []string{ | ||
string(utils.Must1(_root.ReadFile(`script.js`))), | ||
}, | ||
} | ||
sass.WatchDefaultAsync(string(dir.SourceAbsoluteDir())) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
function setupAnniversary(){ | ||
|
||
if (!new Date().toDateString().includes('Dec 24 2024')) { | ||
return; | ||
} | ||
|
||
if (location.pathname != '/') { | ||
return; | ||
} | ||
|
||
const canvas = document.createElement('canvas'); | ||
canvas.classList.add('anniversary'); | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
document.body.appendChild(canvas); | ||
|
||
const ctx = canvas.getContext('2d'); | ||
const emojis = ['🎂', '🎄']; | ||
|
||
const particles = []; | ||
|
||
class Particle { | ||
constructor(x, y, emoji) { | ||
this.x = x; | ||
this.y = y; | ||
this.size = Math.random() * 40 + 20; | ||
this.speed = Math.random() + 1; | ||
this.emoji = emoji; | ||
} | ||
draw() { | ||
ctx.font = `${this.size}px Arial`; | ||
ctx.textAlign = 'center'; | ||
ctx.fillText(this.emoji, this.x, this.y); | ||
} | ||
update() { | ||
this.y += this.speed; | ||
if (this.y > canvas.height) { | ||
this.y = -this.size; | ||
this.x = Math.random() * canvas.width; | ||
} | ||
} | ||
} | ||
|
||
function init() { | ||
for (let i = 0; i < 30; i++) { | ||
const randomEmoji = emojis[Math.floor(Math.random() * emojis.length)]; | ||
const x = Math.random() * canvas.width; | ||
const y = Math.random() * canvas.height - canvas.height; | ||
particles.push(new Particle(x, y, randomEmoji)); | ||
} | ||
} | ||
|
||
let timer = undefined; | ||
timer = setTimeout(function(){ | ||
clearTimeout(timer); | ||
timer = undefined; | ||
}, 10000); | ||
|
||
function animate() { | ||
ctx.clearRect(0, 0, canvas.width, canvas.height); | ||
particles.forEach(particle => { | ||
particle.update(); | ||
particle.draw(); | ||
}); | ||
if (timer) { | ||
requestAnimationFrame(animate); | ||
} else { | ||
canvas.remove(); | ||
} | ||
} | ||
|
||
init(); | ||
animate(); | ||
|
||
window.addEventListener('resize', () => { | ||
particles.length = 0; | ||
canvas.width = window.innerWidth; | ||
canvas.height = window.innerHeight; | ||
init(); | ||
}); | ||
|
||
} | ||
|
||
document.addEventListener('DOMContentLoaded', setupAnniversary); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
canvas.anniversary { | ||
display: block; | ||
box-sizing: border-box; | ||
position: fixed; | ||
left: 0; | ||
top: 0; | ||
width: 100%; | ||
height: 100%; | ||
z-index: -1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters