Skip to content

Commit

Permalink
ee
Browse files Browse the repository at this point in the history
  • Loading branch information
JagGillarVatten committed Aug 29, 2024
1 parent 999c2bc commit c0935ac
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions scripts/gfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,53 @@ return specialDates.some(entry => entry.date === date.toISOString().split("T")[0
function getSpecialDate(date) {
return specialDates.find(entry => entry.date === date.toISOString().split("T")[0]);
}

// Check if snowfall period
function isSnowfallPeriod() {
const startDate = new Date(new Date().getFullYear(), 10, 23);
const endDate = new Date(new Date().getFullYear(), 11, 31);
return new Date() >= startDate && new Date() <= endDate;
const startDate = new Date(new Date().getFullYear(),10 , 23);
const endDate = new Date(new Date().getFullYear(), 12, 31);
return new Date() >= startDate && new Date() <= endDate;
}

// Create snowflake
function createSnowflake() {
const snowflake = document.createElement("div");
snowflake.className = "snowflake";
snowflake.style.left = `${Math.random() * window.innerWidth}px`;
document.body.appendChild(snowflake);
const snowflake = document.createElement("div");
snowflake.className = "snowflake";
snowflake.style.left = `${Math.random() * window.innerWidth}px`;
snowflake.style.position = "fixed";
snowflake.style.top = "-10px";
snowflake.style.fontSize = "20px";
snowflake.style.color = "white";
snowflake.style.opacity = "4030";
snowflake.style.userSelect = "none";
snowflake.style.zIndex = "1000";
snowflake.innerHTML = "❄";
document.body.appendChild(snowflake);

snowflake.addEventListener("animationend", () => {
document.body.removeChild(snowflake);
});
// Animate snowflake
const animationDuration = 5 + Math.random() * 5; // 5-10 seconds
const horizontalMovement = -20 + Math.random() * 40; // -20px to 20px

snowflake.animate([
{ transform: 'translate(0, 0) rotate(0deg)' },
{ transform: `translate(${horizontalMovement}px, ${window.innerHeight}px) rotate(360deg)` }
], {
duration: animationDuration * 1000,
easing: 'linear'
}).onfinish = () => {
document.body.removeChild(snowflake);
};
}

// Start snowfall
function startSnowfall() {
if (isSnowfallPeriod()) {
createSnowflake();
setTimeout(startSnowfall, 200); // Create a new snowflake every 200ms
}
}

// Call startSnowfall when the page loads
window.addEventListener('load', startSnowfall);
// Function to update the background color every second
function updateBackground() {
const currentHour = new Date().getHours();
Expand All @@ -59,8 +86,6 @@ document.body.classList.add("night");
// Set interval for updating background
setInterval(updateBackground, 1000);

// Set interval for creating snowflakes
setInterval(createSnowflake, 50);

// Set interval for updating countdown
setInterval(updateCountdown, 50);
Expand Down

0 comments on commit c0935ac

Please sign in to comment.