forked from vyla-entertainment/home-frontend
updated site and images
This commit is contained in:
@@ -6,6 +6,101 @@ import { DISCORD_LOADER_SCRIPT, COPY_FEEDBACK_DURATION_MS } from '../config/cons
|
||||
|
||||
const HERO_GREETING = 'Vyla Home';
|
||||
|
||||
function initVideoColorExtraction() {
|
||||
const videos = document.querySelectorAll('.hero-atmosphere-video');
|
||||
if (videos.length === 0) return;
|
||||
|
||||
console.log('Video color extraction initialized, found', videos.length, 'videos');
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
const ctx = canvas.getContext('2d', { willReadFrequently: true });
|
||||
let animationFrameId;
|
||||
let frameCount = 0;
|
||||
let currentVideoColor = 'rgb(0, 0, 0)';
|
||||
|
||||
function extractColors() {
|
||||
const video = videos[0];
|
||||
if (video.readyState < 2) {
|
||||
console.log('Video not ready, readyState:', video.readyState);
|
||||
animationFrameId = requestAnimationFrame(extractColors);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
canvas.width = 64;
|
||||
canvas.height = 64;
|
||||
ctx.drawImage(video, 0, 0, 64, 64);
|
||||
const imageData = ctx.getImageData(0, 0, 64, 64);
|
||||
const data = imageData.data;
|
||||
|
||||
let r = 0, g = 0, b = 0;
|
||||
let count = 0;
|
||||
|
||||
for (let i = 0; i < data.length; i += 4) {
|
||||
r += data[i];
|
||||
g += data[i + 1];
|
||||
b += data[i + 2];
|
||||
count++;
|
||||
}
|
||||
|
||||
r = Math.round(r / count);
|
||||
g = Math.round(g / count);
|
||||
b = Math.round(b / count);
|
||||
|
||||
currentVideoColor = `rgb(${r}, ${g}, ${b})`;
|
||||
const dominantColorTransparent = `rgba(${r}, ${g}, ${b}, 0.5)`;
|
||||
|
||||
document.documentElement.style.setProperty('--video-dominant-color', currentVideoColor);
|
||||
document.documentElement.style.setProperty('--video-dominant-color-transparent', dominantColorTransparent);
|
||||
|
||||
if (window.scrollY === 0) {
|
||||
document.documentElement.style.setProperty('--color-bg', currentVideoColor);
|
||||
}
|
||||
|
||||
frameCount++;
|
||||
if (frameCount % 30 === 0) {
|
||||
console.log('Frame', frameCount, '- Extracted color:', currentVideoColor);
|
||||
console.log('CSS variable set:', getComputedStyle(document.documentElement).getPropertyValue('--video-dominant-color'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Error extracting video colors:', e);
|
||||
}
|
||||
|
||||
animationFrameId = requestAnimationFrame(extractColors);
|
||||
}
|
||||
|
||||
function handleScroll() {
|
||||
const scrollY = window.scrollY;
|
||||
const heroHeight = window.innerHeight;
|
||||
const scrollProgress = Math.min(scrollY / (heroHeight * 0.5), 1);
|
||||
|
||||
const videoColorRGB = currentVideoColor.match(/\d+/g);
|
||||
if (videoColorRGB) {
|
||||
const r = Math.round(parseInt(videoColorRGB[0]) * (1 - scrollProgress));
|
||||
const g = Math.round(parseInt(videoColorRGB[1]) * (1 - scrollProgress));
|
||||
const b = Math.round(parseInt(videoColorRGB[2]) * (1 - scrollProgress));
|
||||
const fadedColor = `rgb(${r}, ${g}, ${b})`;
|
||||
document.documentElement.style.setProperty('--color-bg', fadedColor);
|
||||
}
|
||||
}
|
||||
|
||||
animationFrameId = requestAnimationFrame(extractColors);
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
handleScroll();
|
||||
|
||||
videos.forEach(video => {
|
||||
video.addEventListener('pause', () => {
|
||||
console.log('Video paused, stopping color extraction');
|
||||
cancelAnimationFrame(animationFrameId);
|
||||
});
|
||||
|
||||
video.addEventListener('play', () => {
|
||||
console.log('Video playing, starting color extraction');
|
||||
animationFrameId = requestAnimationFrame(extractColors);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function initHeroTitle() {
|
||||
const heroTitle = qs('.hero-title');
|
||||
if (heroTitle) typewriterReveal(heroTitle, HERO_GREETING);
|
||||
@@ -48,8 +143,7 @@ export function initHeroSection() {
|
||||
initDiscordCopyBar();
|
||||
initHeroCopyButton();
|
||||
initCtaCopyButton();
|
||||
if (!isMobileViewport()) {
|
||||
initFluidByteField('hero-byte-overlay');
|
||||
initFluidByteField('cta-byte-overlay');
|
||||
}
|
||||
initVideoColorExtraction();
|
||||
initFluidByteField('hero-byte-overlay');
|
||||
initFluidByteField('cta-byte-overlay');
|
||||
}
|
||||
Reference in New Issue
Block a user