Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
  • Loading branch information
i1li committed Aug 18, 2024
1 parent d5acd3d commit cd05a22
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 60 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ My favorite features are the <a href="#Lightest YouTube Embed">custom video embe
<b>Quickstart:</b> Use a quick deploy button above, or clone this repo locally, open a terminal in the project directory,<br/> & enter either:</p>

```bash
npm i express
npm i dotenv
npm i express dotenv
node serv.js
```
<p align="center">(the simplest option), or, if you'd like to use Netlify's <a href="https://www.netlify.com/platform/core/functions/">serverless functions</a>, enter the following. (<a href="#Netlify Content Gate">example of serverless function.</a>)
Expand Down
3 changes: 3 additions & 0 deletions css/background.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
top: 0;
left: 0;
}
#box {
mix-blend-mode: difference;
}
#overlay {
mix-blend-mode: overlay;
}
5 changes: 3 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ a:hover {text-decoration: dotted underline;
background: linear-gradient(to top, rgba(22,22,222, .2), rgba(22, 222, 222, .5));}
article {min-height:80vh; border: dotted 1px rgba(255,255,0,.1);}
.article-header {background-image: url("/img/bg.png");
transition: all .55s ease-in;
transition: all 1.1s ease-in;
background-size: 191px;
background-attachment: scroll;
border: solid 1px rgba(0,255,0,.15);
Expand All @@ -158,7 +158,8 @@ article {min-height:80vh; border: dotted 1px rgba(255,255,0,.1);}
padding-bottom: .1em;
filter: drop-shadow(0 0 1em black);
backdrop-filter: brightness(115%) contrast(150%) saturate(300%);}
.article-header:hover {backdrop-filter: brightness(65%) saturate(300%) contrast(100%); scale: 1.01; filter: drop-shadow(0 0 1.5em black);}
.article-header:hover {backdrop-filter: brightness(150%) saturate(300%) contrast(150%); scale: 1.01; filter: drop-shadow(0 0 1.5em rgba(0, 0, 0, 0.5));
background-blend-mode: saturation;}
.article-header-wrapper {background: linear-gradient(to bottom, rgba(0, 222, 0, .15), rgba(128, 22, 128, 0.3));
transition: all 1.1s ease-out;
margin-right: -.7em;
Expand Down
22 changes: 11 additions & 11 deletions index.html

Large diffs are not rendered by default.

124 changes: 84 additions & 40 deletions js/background.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,90 @@
// Only run this code on non-mobile devices
if (detectMobile()) {
const box = document.getElementById("box");
const overlay = document.getElementById("overlay");
let hueIndex = 0;
let intervalCount = 0;
let isWindowActive = true;
window.addEventListener('focus', () => isWindowActive = true);
window.addEventListener('blur', () => isWindowActive = false);
function getRandomHueIncrement() {return Math.random() < 0.5 ? Math.random() * -.75 - .75 : Math.random() * .75 + .75;}
let hueIncrement = getRandomHueIncrement();
function getIntervalsTillNextChange() {return Math.floor(Math.random() * 66) + 33;}
let intervalsTillNextChange = getIntervalsTillNextChange();
const HUE_STEP = 360 / 7;
function getAdjustedHue(index, step) {return (index + step * HUE_STEP + 360) % 360;}
function setGradient(element, index) {
const width = element.offsetWidth;
const height = element.offsetHeight;
const diagonal = Math.sqrt(width * width + height * height);
const percentage = (diagonal / (Math.max(width, height) * Math.sqrt(2))) * 100;
let gradients = [];
for (let i = 0; i < 7; i++) {
const angle = i * (360 / 7);
const x = 50 + 50 * Math.cos(angle * Math.PI / 180);
const y = 50 + 50 * Math.sin(angle * Math.PI / 180);
gradients.push(`radial-gradient(ellipse farthest-corner at ${x}% ${y}%, hsl(${getAdjustedHue(index, i)}, 100%, 50%), transparent ${percentage}%)`);
}
element.style.backgroundImage = gradients.join(', ');
}
function updateColors() {
const box = document.getElementById("box");
const overlay = document.getElementById("overlay");
let isWindowActive = true;
window.addEventListener('focus', () => isWindowActive = true);
window.addEventListener('blur', () => isWindowActive = false);
function getRandomHueIncrement() {
return Math.random() < 0.5 ? Math.random() * -0.75 - 0.75 : Math.random() * 0.75 + 0.75;
}
function getIntervalsTillNextChange() {
return Math.floor(Math.random() * 72) + 72;
}
function getRandomOverlayOffset() {
return Math.random() * 11 + 3;
}
const BOX_HUE_STEP = 7;
const BOX_HUE_ANGLE = 360 / BOX_HUE_STEP;
function getAdjustedHue(index, step, hueAngle) {
return (index + step * hueAngle + 360) % 360;
}
function createLayerState(isOverlay) {
return {
hueIndex: 0,
hueIncrement: getRandomHueIncrement(),
intervalCount: 0,
intervalsTillNextChange: getIntervalsTillNextChange(),
currentOverlayOffset: isOverlay ? getRandomOverlayOffset() : 0,
targetOverlayOffset: isOverlay ? getRandomOverlayOffset() : 0,
transitionProgress: 0,
transitionDuration: isOverlay ? getIntervalsTillNextChange() : 0,
hueStep: isOverlay ? getRandomOverlayOffset() : BOX_HUE_STEP
};
}
let boxState = createLayerState(false);
let overlayState = createLayerState(true);
function easeInOutCubic(t) {
return t < 0.5 ? 4 * t * t * t : 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function setGradient(element, state, isOverlay = false) {
const width = element.offsetWidth;
const height = element.offsetHeight;
const diagonal = Math.sqrt(width * width + height * height);
const percentage = (diagonal / (Math.max(width, height) * Math.sqrt(2))) * 100;
let gradients = [];
const hueStep = state.hueStep;
const hueAngle = 360 / hueStep;
for (let i = 0; i < hueStep; i++) {
const angle = i * hueAngle;
const x = 50 + 50 * Math.cos(angle * Math.PI / 180);
const y = 50 + 50 * Math.sin(angle * Math.PI / 180);
const currentStep = isOverlay ? i + state.currentOverlayOffset : i;
gradients.push(`radial-gradient(ellipse farthest-corner at ${x}% ${y}%, hsl(${getAdjustedHue(state.hueIndex, currentStep, hueAngle)}, 100%, 50%), transparent ${percentage}%)`);
}
element.style.backgroundImage = gradients.join(', ');
}
function updateLayerState(state, isOverlay) {
state.hueIndex = (state.hueIndex + state.hueIncrement + 360) % 360;
state.intervalCount++;
if (state.intervalCount >= state.intervalsTillNextChange) {
state.hueIncrement = getRandomHueIncrement();
if (isOverlay) {
state.targetOverlayOffset = getRandomOverlayOffset();
state.transitionDuration = getIntervalsTillNextChange();
}
state.intervalCount = 0;
state.intervalsTillNextChange = getIntervalsTillNextChange();
}
if (isOverlay) {
state.transitionProgress += .002 / state.transitionDuration;
if (state.transitionProgress >= 1) {
state.transitionProgress = 0;
state.currentOverlayOffset = state.targetOverlayOffset;
} else {
state.currentOverlayOffset += (state.targetOverlayOffset - state.currentOverlayOffset) * easeInOutCubic(state.transitionProgress);
}
}
}
function updateColors() {
if (isWindowActive) {
hueIndex = (hueIndex + hueIncrement + 360) % 360;
intervalCount++;
if (intervalCount >= intervalsTillNextChange) {
hueIncrement = getRandomHueIncrement();
intervalCount = 0;
intervalsTillNextChange = getIntervalsTillNextChange();
updateLayerState(boxState, false);
updateLayerState(overlayState, true);
setGradient(box, boxState);
setGradient(overlay, overlayState, true);
}
setGradient(box, hueIndex);
setGradient(overlay, 360 - hueIndex);
}
}
setGradient(box, 0);
setGradient(overlay, 360);
setInterval(updateColors, 33);
setGradient(box, boxState);
setGradient(overlay, overlayState, true);
setInterval(updateColors, 33);
}
10 changes: 5 additions & 5 deletions js/color-change.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Only run this code on non-mobile devices
if (detectMobile()) {
const hoverShift = document.querySelectorAll('button, a, a.dark-mode, .article-header-wrapper, footer, .article-nav-bottom, #site-nav a, .section-nav a');
const hoverShift = document.querySelectorAll('button, a, a.dark-mode, footer, .article-nav-bottom, #site-nav a, .section-nav a');
const alwaysShift = document.querySelectorAll('header, #site-nav .col, .section-nav .col, .article-header, footer, .article-title, #site-title, #light-dark-zoom');
function getRandomDegree() {return Math.random() < 0.5 ? Math.floor(Math.random() * -270) - 45 : Math.floor(Math.random() * 270) + 46;}
function getNewIntervalsTillNextChange() {return Math.floor(Math.random() * 22) + 11;}
Expand Down Expand Up @@ -49,10 +49,10 @@ function startShift(element, interval, isHover = false) {
intervalCount = 0;
intervalsTillNextChange = getNewIntervalsTillNextChange();
}
currentDegree += (targetDegree - currentDegree) * 0.05;
currentSaturation += (targetSaturation - currentSaturation) * 0.05;
currentContrast += (targetContrast - currentContrast) * 0.05;
currentBrightness += (targetBrightness - currentBrightness) * 0.05;
currentDegree += (targetDegree - currentDegree) * 0.01;
currentSaturation += (targetSaturation - currentSaturation) * 0.01;
currentContrast += (targetContrast - currentContrast) * 0.01;
currentBrightness += (targetBrightness - currentBrightness) * 0.01;
updateFilter();
}
}, interval);
Expand Down

0 comments on commit cd05a22

Please sign in to comment.