Skip to content

Commit

Permalink
Christmas Update
Browse files Browse the repository at this point in the history
new: Experience snowfall during the holidays
new: Performance optimisations to go along with the snowfall effect
  • Loading branch information
lscambo13 committed Dec 25, 2023
1 parent 62926ce commit eb89214
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 7 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

<body onclick="hideWallpapers('body', null)">
<div id="overlay"></div>
<canvas id="canvasFar"></canvas>
<div id="gradient_overlay"></div>
<div id="header" class="header">
<div class="header-left-block">
Expand Down
19 changes: 13 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ import { intersectionObserver } from './js_modules/utils/intersectionObserver.js
import { getLastUpdated } from './js_modules/utils/getLastUpdated.js';
import { displayFlex } from './js_modules/utils/displayStyles.js';
import { blurLevel } from './js_modules/utils/blurLevel.js';
import { isItChristmas } from './js_modules/utils/letItSnow.js';

const bottomFilmRollContainer = document.getElementById('wallpapers');
const wrap = document.getElementById('wrap');
const advancedSettingsButton = document.getElementById('toggle-labs-btn');


let timeout;
window.hideWallpapers = (str, event) => {
if (event) {
Expand Down Expand Up @@ -97,18 +99,19 @@ window.hideWallpapers = (str, event) => {
bottomFilmRollContainer.classList[1] == 'animation_slide_down'
) {
blurLevel(0);
document.title = document.title
.replace('Search', 'Backgrounds');
bottomFilmRollContainer.classList.remove('animation_slide_down');
bottomFilmRollContainer.classList.add('animation_slide_up');
wrap.classList.remove('animation2_slide_down', 'startup_slide_down');
wrap.classList.add('animation2_slide_up');
setTimeout(() => advancedSettingsButton.classList
.add('animation_slide_right'), 350);
setTimeout(() => {
advancedSettingsButton.classList.add('animation_slide_right')
scrollHighlightedWallpaperIntoView();
}, 350);
changeGlow(null, 1);
timeout = setTimeout(() => toggleRemoveButtons('show'), 450);
toggleArrows('show');
scrollHighlightedWallpaperIntoView();
document.title = document.title
.replace('Search', 'Backgrounds');
} else {
document.title = document.title
.replace('Backgrounds', 'Search');
Expand Down Expand Up @@ -209,7 +212,10 @@ addEventListenerOnID('right-arrow', 'click', (event) => {
changeSlide('widget-slide', -1);
});

window.addEventListener('resize', applyPreferences);
window.addEventListener('resize', () => {
applyPreferences();
isItChristmas()
});

// addEventListenerOnID('wallpapers', 'wheel', (e) => {
// // e.stopPropagation();
Expand Down Expand Up @@ -286,6 +292,7 @@ document.addEventListener('DOMContentLoaded', async () => {
scrollToBottom();
focusSearchBar('auto');
getLastUpdated('version-preview');
isItChristmas();
});

// ---------------------------------------------------------- End
Expand Down
4 changes: 4 additions & 0 deletions js_modules/modals/advanced_settings.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { blurLevel } from "../utils/blurLevel.js";

const modal = document.getElementById('advanced-settings-modal');
const modalBackground =
document.getElementById('advanced-settings-modal-background-overlay');

export function openAdvancedSettings() {
setTimeout(() => blurLevel(0), 420)
document.title = document.title.replace('Backgrounds', 'Settings');
modal.style.display = 'block';
modalBackground.style.display = 'block';
Expand All @@ -12,4 +15,5 @@ export function closeAdvancedSettings() {
document.title = document.title.replace('Settings', 'Search');
modal.style.display = 'none';
modalBackground.style.display = 'none';
setTimeout(() => blurLevel(1), 100)
};
2 changes: 1 addition & 1 deletion js_modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function scrollHighlightedWallpaperIntoView() {
const wallpaper = document.getElementsByClassName('highlighted')[0];
setTimeout(() => {
if (wallpaper) wallpaper.scrollIntoView({ inline: 'center' });
}, 50);
}, 10);
};

export async function stylizeText(id, int = 0) {
Expand Down
2 changes: 2 additions & 0 deletions js_modules/utils/blurLevel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export function blurLevel(int) {
document.documentElement.style
.setProperty('--blur-one-em', `blur(${int}em)`);
document.documentElement.style
.setProperty('--blur-one-px', `blur(${int}px)`);
}
98 changes: 98 additions & 0 deletions js_modules/utils/letItSnow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
let pause = false
export function pauseSnaowfall(boolean) {
pause = boolean
isItChristmas()
}
export function isItChristmas() {
let date = new Date()
if (date.getMonth() == 11 && date.getDate() > 17 && date.getDate() < 32) {
// console.log(date.getMonth() == 11, date.getDate() > 17, date.getDate() < 32)
letItSnow()
}
}
function letItSnow() {
pause = true
//canvas init
var canvas = document.getElementById("canvasFar");
var ctx = canvas.getContext("2d");

//canvas dimensions
var W = window.innerWidth;
var H = window.innerHeight;
canvas.width = W;
canvas.height = H;

//snowflake particles
var mp = 20; //max particles
var particles = [];
for (var i = 0; i < mp; i++) {
particles.push({
x: Math.random() * W, //x-coordinate
y: Math.random() * H, //y-coordinate
r: Math.random() * 4 + 1, //radius
d: Math.random() * mp //density
})
}

//Lets draw the flakes
ctx.fillStyle = "rgba(255, 255, 255, 1)";
function draw() {
// let tStart = Date.now()
ctx.clearRect(0, 0, W, H);
ctx.beginPath();
for (var i = 0; i < mp; i++) {
var p = particles[i];
ctx.moveTo(p.x, p.y);
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2, true);
}
ctx.fill();
update();
if (!pause) window.requestAnimationFrame(draw);
// console.log(Date.now() - tStart)
// console.log('draw')
}

//Function to move the snowflakes
//angle will be an ongoing incremental flag. Sin and Cos functions will be applied to it to create vertical and horizontal movements of the flakes
// var angle = 0;
function update() {
// console.log('update main')
// angle += 0.01;
for (var i = 0; i < mp; i++) {
// console.log('update loop')
var p = particles[i];
//Updating X and Y coordinates
//We will add 1 to the cos function to prevent negative values which will lead flakes to move upwards
//Every particle has its own density which can be used to make the downward movement different for each flake
//Lets make it more random by adding in the radius
p.y += Math.cos(p.d) + 1 + p.r / 2;
// p.y += Math.cos(angle + p.d) + 1 + p.r / 2;
// p.x += Math.sin(angle) * 2;

//Sending flakes back from the top when it exits
//Lets make it a bit more organic and let flakes enter from the left and right also.
if (p.x > W + 5 || p.x < -5 || p.y > H) {
if (i % 3 > 0) //66.67% of the flakes
{
particles[i] = { x: Math.random() * W, y: -10, r: p.r, d: p.d };
}
// else {
// //If the flake is exitting from the right
// if (Math.sin(angle) > 0) {
// //Enter from the left
// particles[i] = { x: -5, y: Math.random() * H, r: p.r, d: p.d };
// }
// else {
// //Enter from the right
// particles[i] = { x: W + 5, y: Math.random() * H, r: p.r, d: p.d };
// }
// }
}
}
}
canvas.style.display = 'block'
pause = false
window.requestAnimationFrame(draw);
//animation loop
// setInterval(draw, 60);
}
14 changes: 14 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--primary-color: #faf7f0ff;
--secondary-color: #e7decdff;
--blur-one-em: blur(1em);
--blur-one-px: blur(1px);
--blur-half-em: blur(0.5em);
--cross-display: none;
--removable-border: .075em solid var(--primary-color);
Expand Down Expand Up @@ -42,6 +43,17 @@
background: var(--selection-color);
}

#canvasFar {
position: fixed;
display: none;
z-index: 0;
/* background: rgba(255, 255, 255, 0.25); */
background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.25) 0%, rgba(235, 235, 255, 0) 60%);
/* filter: var(--blur-one-px); */
backdrop-filter: var(--blur-one-px);
-webkit-backdrop-filter: var(--blur-one-px);
}

.disable-select {
-webkit-user-select: none;
-moz-user-select: none;
Expand Down Expand Up @@ -710,6 +722,7 @@ body::-webkit-scrollbar {
font-family: Ubuntu;
/* backdrop-filter: var( --blur-one-em);
-webkit-backdrop-filter: var( --blur-one-em); */
z-index: 3;
cursor: default;
display: none;
/* transition: 300ms; */
Expand Down Expand Up @@ -739,6 +752,7 @@ body::-webkit-scrollbar {
}

.modal-group {
position: relative;
display: flex;
flex-direction: column;
margin: .75em;
Expand Down

0 comments on commit eb89214

Please sign in to comment.