// ============================================ // Initialize Lucide Icons // ============================================ lucide.createIcons(); // ============================================ // Custom Cursor // ============================================ const cursorDot = document.getElementById('cursorDot'); const cursorRing = document.getElementById('cursorRing'); let mouseX = 0, mouseY = 0; let ringX = 0, ringY = 0; document.addEventListener('mousemove', e => { mouseX = e.clientX; mouseY = e.clientY; cursorDot.style.left = mouseX - 4 + 'px'; cursorDot.style.top = mouseY - 4 + 'px'; }); function animateCursor() { ringX += (mouseX - ringX) * 0.15; ringY += (mouseY - ringY) * 0.15; cursorRing.style.left = ringX - 20 + 'px'; cursorRing.style.top = ringY - 20 + 'px'; requestAnimationFrame(animateCursor); } animateCursor(); // Hover effect on interactive elements document.querySelectorAll('.interactive-hover, a, button, input, textarea').forEach(el => { el.addEventListener('mouseenter', () => cursorRing.classList.add('hover')); el.addEventListener('mouseleave', () => cursorRing.classList.remove('hover')); }); // ============================================ // Particle Background // ============================================ const particleCanvas = document.getElementById('particleBg'); const pCtx = particleCanvas.getContext('2d'); let particles = []; function resizeParticleCanvas() { particleCanvas.width = window.innerWidth; particleCanvas.height = window.innerHeight; } resizeParticleCanvas(); window.addEventListener('resize', resizeParticleCanvas); class Particle { constructor() { this.reset(); } reset() { this.x = Math.random() * particleCanvas.width; this.y = Math.random() * particleCanvas.height; this.size = Math.random() * 1.5 + 0.5; this.speedX = (Math.random() - 0.5) * 0.3; this.speedY = (Math.random() - 0.5) * 0.3; this.opacity = Math.random() * 0.3 + 0.05; } update() { this.x += this.speedX; this.y += this.speedY; if (this.x < 0 || this.x > particleCanvas.width) this.speedX *= -1; if (this.y < 0 || this.y > particleCanvas.height) this.speedY *= -1; } draw() { pCtx.beginPath(); pCtx.arc(this.x, this.y, this.size, 0, Math.PI * 2); pCtx.fillStyle = `rgba(255,255,255,${this.opacity})`; pCtx.fill(); } } for (let i = 0; i < 80; i++) { particles.push(new Particle()); } function animateParticles() { pCtx.clearRect(0, 0, particleCanvas.width, particleCanvas.height); // Draw connections for (let i = 0; i < particles.length; i++) { for (let j = i + 1; j < particles.length; j++) { const dx = particles[i].x - particles[j].x; const dy = particles[i].y - particles[j].y; const dist = Math.sqrt(dx * dx + dy * dy); if (dist < 150) { pCtx.beginPath(); pCtx.moveTo(particles[i].x, particles[i].y); pCtx.lineTo(particles[j].x, particles[j].y); pCtx.strokeStyle = `rgba(255,255,255,${0.03 * (1 - dist / 150)})`; pCtx.lineWidth = 0.5; pCtx.stroke(); } } } particles.forEach(p => { p.update(); p.draw(); }); requestAnimationFrame(animateParticles); } animateParticles(); // ============================================ // Scroll Reveal Animations // ============================================ const revealElements = document.querySelectorAll('.reveal, .reveal-left, .reveal-right, .draw-line'); const revealObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('active'); } }); }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' }); revealElements.forEach(el => revealObserver.observe(el)); // ============================================ // Counter Animation // ============================================ const counters = document.querySelectorAll('.counter'); let counterAnimated = false; const counterObserver = new IntersectionObserver((entries) => { entries.forEach(entry => { if (entry.isIntersecting && !counterAnimated) { counterAnimated = true; counters.forEach(counter => { const target = parseInt(counter.dataset.target); let current = 0; const step = target / 60; const updateCounter = () => { current += step; if (current < target) { counter.textContent = Math.ceil(current) + '+'; requestAnimationFrame(updateCounter); } else { counter.textContent = target + '+'; } }; updateCounter(); }); } }); }, { threshold: 0.5 }); counters.forEach(c => counterObserver.observe(c)); // ============================================ // Navbar Scroll Effect // ============================================ const navbar = document.getElementById('navbar'); let lastScroll = 0; window.addEventListener('scroll', () => { const currentScroll = window.scrollY; if (currentScroll > 80) { navbar.style.background = 'rgba(10,10,10,0.85)'; navbar.style.backdropFilter = 'blur(20px)'; navbar.style.borderBottom = '1px solid rgba(255,255,255,0.05)'; } else { navbar.style.background = 'transparent'; navbar.style.backdropFilter = 'none'; navbar.style.borderBottom = 'none'; } lastScroll = currentScroll; }); // ============================================ // Mobile Menu // ============================================ const mobileMenuBtn = document.getElementById('mobileMenuBtn'); const mobileMenu = document.getElementById('mobileMenu'); mobileMenuBtn.addEventListener('click', () => { mobileMenu.classList.toggle('hidden'); }); document.querySelectorAll('.mobile-link').forEach(link => { link.addEventListener('click', () => { mobileMenu.classList.add('hidden'); }); }); // ============================================ // Project Filter // ============================================ const filterBtns = document.querySelectorAll('.filter-btn'); const projectCards = document.querySelectorAll('.project-card'); filterBtns.forEach(btn => { btn.addEventListener('click', () => { filterBtns.forEach(b => { b.classList.remove('active', 'text-white', 'bg-white/5'); b.classList.add('text-neutral-500'); }); btn.classList.add('active', 'text-white', 'bg-white/5'); btn.classList.remove('text-neutral-500'); const filter = btn.dataset.filter; projectCards.forEach(card => { if (filter === 'all' || card.dataset.category === filter) { card.style.display = ''; card.style.opacity = '0'; card.style.transform = 'translateY(20px)'; requestAnimationFrame(() => { card.style.transition = 'all 0.5s ease'; card.style.opacity = '1'; card.style.transform = 'translateY(0)'; }); } else { card.style.opacity = '0'; card.style.transform = 'translateY(20px)'; setTimeout(() => { card.style.display = 'none'; }, 400); } }); }); }); // ============================================ // Tilt Card Effect // ============================================ document.querySelectorAll('.tilt-card, .project-card').forEach(card => { card.addEventListener('mousemove', e => { const rect = card.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; const centerX = rect.width / 2; const centerY = rect.height / 2; const rotateX = (y - centerY) / 20; const rotateY = (centerX - x) / 20; card.style.transform = `perspective(1000px) rotateX(${rotateX}deg) rotateY(${rotateY}deg)`; }); card.addEventListener('mouseleave', () => { card.style.transform = 'perspective(1000px) rotateX(0) rotateY(0)'; }); }); // ============================================ // Magnetic Buttons // ============================================ document.querySelectorAll('.magnetic-btn').forEach(btn => { btn.addEventListener('mousemove', e => { const rect = btn.getBoundingClientRect(); const x = e.clientX - rect.left - rect.width / 2; const y = e.clientY - rect.top - rect.height / 2; btn.style.transform = `translate(${x * 0.3}px, ${y * 0.3}px)`; }); btn.addEventListener('mouseleave', () => { btn.style.transform = 'translate(0, 0)'; }); }); // ============================================ // Interactive Doodle Canvas // ============================================ const doodleCanvas = document.getElementById('interactiveDoodleCanvas'); const dCtx = doodleCanvas.getContext('2d'); let isDrawing = false; let currentSticker = null; let doodlePaths = []; let currentPath = []; let stickerPositions = []; function resizeDoodleCanvas() { const rect = doodleCanvas.getBoundingClientRect(); doodleCanvas.width = rect.width; doodleCanvas.height = rect.height; redrawDoodles(); } function redrawDoodles() { dCtx.clearRect(0, 0, doodleCanvas.width, doodleCanvas.height); // Draw freehand paths doodlePaths.forEach(path => { if (path.length < 2) return; dCtx.beginPath(); dCtx.moveTo(path[0].x, path[0].y); for (let i = 1; i < path.length; i++) { dCtx.lineTo(path[i].x, path[i].y); } dCtx.strokeStyle = 'rgba(255,255,255,0.6)'; dCtx.lineWidth = 1.5; dCtx.lineCap = 'round'; dCtx.lineJoin = 'round'; dCtx.stroke(); }); // Draw stickers stickerPositions.forEach(sticker => { drawSticker(sticker.type, sticker.x, sticker.y); }); } function drawSticker(type, cx, cy) { dCtx.save(); dCtx.translate(cx, cy); dCtx.strokeStyle = 'rgba(255,255,255,0.5)'; dCtx.lineWidth = 1.5; switch(type) { case 'star': dCtx.beginPath(); for (let i = 0; i < 5; i++) { const angle = (i * 4 * Math.PI) / 5 - Math.PI / 2; const method = i === 0 ? 'moveTo' : 'lineTo'; dCtx[method](Math.cos(angle) * 20, Math.sin(angle) * 20); } dCtx.closePath(); dCtx.stroke(); break; case 'circle': dCtx.beginPath(); dCtx.arc(0, 0, 18, 0, Math.PI * 2); dCtx.stroke(); dCtx.beginPath(); dCtx.arc(0, 0, 8, 0, Math.PI * 2); dCtx.stroke(); break; case 'heart': dCtx.beginPath(); dCtx.moveTo(0, 8); dCtx.bezierCurveTo(-20, -12, -20, -22, 0, -10); dCtx.bezierCurveTo(20, -22, 20, -12, 0, 8); dCtx.stroke(); break; case 'diamond': dCtx.beginPath(); dCtx.moveTo(0, -20); dCtx.lineTo(15, 0); dCtx.lineTo(0, 20); dCtx.lineTo(-15, 0); dCtx.closePath(); dCtx.stroke(); break; case 'spiral': dCtx.beginPath(); for (let i = 0; i < 300; i++) { const angle = i * 0.1; const r = i * 0.06; dCtx.lineTo(Math.cos(angle) * r, Math.sin(angle) * r); } dCtx.stroke(); break; } dCtx.restore(); } doodleCanvas.addEventListener('mousedown', e => { if (currentSticker) { const rect = doodleCanvas.getBoundingClientRect(); const x = e.clientX - rect.left; const y = e.clientY - rect.top; stickerPositions.push({ type: currentSticker, x, y }); redrawDoodles(); return; } isDrawing = true; const rect = doodleCanvas.getBoundingClientRect(); currentPath = [{ x: e.clientX - rect.left, y: e.clientY - rect.top }]; }); doodleCanvas.addEventListener('mousemove', e => { if (!isDrawing) return; const rect = doodleCanvas.getBoundingClientRect(); const point = { x: e.clientX - rect.left, y: e.clientY - rect.top }; currentPath.push(point); dCtx.beginPath(); if (currentPath.length >= 2) { const prev = currentPath[currentPath.length - 2]; dCtx.moveTo(prev.x, prev.y); dCtx.lineTo(point.x, point.y); } dCtx.strokeStyle = 'rgba(255,255,255,0.6)'; dCtx.lineWidth = 1.5; dCtx.lineCap = 'round'; dCtx.lineJoin = 'round'; dCtx.stroke(); }); doodleCanvas.addEventListener('mouseup', () => { if (isDrawing && currentPath.length > 0) { doodlePaths.push(currentPath); currentPath = []; } isDrawing = false; }); doodleCanvas.addEventListener('mouseleave', () => { if (isDrawing && currentPath.length > 0) { doodlePaths.push(currentPath); currentPath = []; } isDrawing = false; }); // Touch support for doodle canvas doodleCanvas.addEventListener('touchstart', e => { e.preventDefault(); const touch = e.touches[0]; if (currentSticker) { const rect = doodleCanvas.getBoundingClientRect(); stickerPositions.push({ type: currentSticker, x: touch.clientX - rect.left, y: touch.clientY - rect.top }); redrawDoodles(); return; } isDrawing = true; const rect = doodleCanvas.getBoundingClientRect(); currentPath = [{ x: touch.clientX - rect.left, y: touch.clientY - rect.top }]; }); doodleCanvas.addEventListener('touchmove', e => { e.preventDefault(); if (!isDrawing) return; const touch = e.touches[0]; const rect = doodleCanvas.getBoundingClientRect(); const point = { x: touch.clientX - rect.left, y: touch.clientY - rect.top }; currentPath.push(point); dCtx.beginPath(); if (currentPath.length >= 2) { const prev = currentPath[currentPath.length - 2]; dCtx.moveTo(prev.x, prev.y); dCtx.lineTo(point.x, point.y); } dCtx.strokeStyle = 'rgba(255,255,255,0.6)'; dCtx.lineWidth = 1.5; dCtx.lineCap = 'round'; dCtx.lineJoin = 'round'; dCtx.stroke(); }); doodleCanvas.addEventListener('touchend', () => { if (isDrawing && currentPath.length > 0) { doodlePaths.push(currentPath); currentPath = []; } isDrawing = false; }); // Double click to clear doodleCanvas.addEventListener('dblclick', () => { doodlePaths = []; stickerPositions = []; dCtx.clearRect(0, 0, doodleCanvas.width, doodleCanvas.height); showToast('Canvas cleared ✨'); }); // Sticker buttons document.querySelectorAll('[data-sticker]').forEach(btn => { btn.addEventListener('click', () => { currentSticker = btn.dataset.sticker; document.querySelectorAll('[data-sticker]').forEach(b => b.classList.remove('bg-white/5', 'text-white')); btn.classList.add('bg-white/5', 'text-white'); showToast(`Sticker mode: ${currentSticker} ☆`); }); }); document.getElementById('clearDoodle').addEventListener('click', () => { doodlePaths = []; stickerPositions = []; currentSticker = null; document.querySelectorAll('[data-sticker]').forEach(b => b.classList.remove('bg-white/5', 'text-white')); dCtx.clearRect(0, 0, doodleCanvas.width, doodleCanvas.height); showToast('Canvas cleared ✨'); }); // Resize doodle canvas on load window.addEventListener('load', resizeDoodleCanvas); window.addEventListener('resize', () => { resizeDoodleCanvas(); }); // ============================================ // Drawing Mode (overlay doodle) // ============================================ const doodleOverlay = document.getElementById('doodleCanvas'); const oCtx = doodleOverlay.getContext('2d'); let drawingMode = false; let overlayDrawing = false; let overlayPaths = []; let overlayCurrentPath = []; function resizeOverlayCanvas() { doodleOverlay.width = window.innerWidth; doodleOverlay.height = window.innerHeight; redrawOverlay(); } function redrawOverlay() { oCtx.clearRect(0, 0, doodleOverlay.width, doodleOverlay.height); overlayPaths.forEach(path => { if (path.length < 2) return; oCtx.beginPath(); oCtx.moveTo(path[0].x, path[0].y); for (let i = 1; i < path.length; i++) { oCtx.lineTo(path[i].x, path[i].y); } oCtx.strokeStyle = 'rgba(255,255,255,0.15)'; oCtx.lineWidth = 2; oCtx.lineCap = 'round'; oCtx.lineJoin = 'round'; oCtx.stroke(); }); } function toggleDrawingMode() { drawingMode = !drawingMode; const btn = document.getElementById('doodleToggle'); if (drawingMode) { doodleOverlay.style.pointerEvents = 'auto'; doodleOverlay.style.cursor = 'crosshair'; btn.classList.add('bg-white/10'); showToast('Drawing mode ON ✏️ Draw anywhere!'); } else { doodleOverlay.style.pointerEvents = 'none'; doodleOverlay.style.cursor = 'default'; btn.classList.remove('bg-white/10'); showToast('Drawing mode OFF'); } } document.getElementById('doodleToggle').addEventListener('click', toggleDrawingMode); doodleOverlay.addEventListener('mousedown', e => { if (!drawingMode) return; overlayDrawing = true; overlayCurrentPath = [{ x: e.clientX, y: e.clientY }]; }); doodleOverlay.addEventListener('mousemove', e => { if (!overlayDrawing) return; const point = { x: e.clientX, y: e.clientY }; overlayCurrentPath.push(point); oCtx.beginPath(); if (overlayCurrentPath.length >= 2) { const prev = overlayCurrentPath[overlayCurrentPath.length - 2]; oCtx.moveTo(prev.x, prev.y); oCtx.lineTo(point.x, point.y); } oCtx.strokeStyle = 'rgba(255,255,255,0.15)'; oCtx.lineWidth = 2; oCtx.lineCap = 'round'; oCtx.lineJoin = 'round'; oCtx.stroke(); }); doodleOverlay.addEventListener('mouseup', () => { if (overlayDrawing && overlayCurrentPath.length > 0) { overlayPaths.push(overlayCurrentPath); overlayCurrentPath = []; } overlayDrawing = false; }); window.addEventListener('resize', resizeOverlayCanvas); resizeOverlayCanvas(); // ============================================ // Toast Notification // ============================================ function showToast(message) { const toast = document.getElementById('toast'); const toastMsg = document.getElementById('toastMsg'); toastMsg.textContent = message; toast.classList.add('show'); setTimeout(() => toast.classList.remove('show'), 2500); } // ============================================ // Contact Form // ============================================ document.getElementById('contactForm').addEventListener('submit', e => { e.preventDefault(); showToast('Message sent successfully! 👻'); e.target.reset(); }); // ============================================ // Magnetic effect for stickers // ============================================ document.querySelectorAll('.sticker').forEach(sticker => { sticker.addEventListener('mousemove', e => { const rect = sticker.getBoundingClientRect(); const x = e.clientX - rect.left - rect.width / 2; const y = e.clientY - rect.top - rect.height / 2; sticker.style.transform = `translate(${x * 0.2}px, ${y * 0.2}px)`; }); sticker.addEventListener('mouseleave', () => { sticker.style.transform = ''; }); }); // ============================================ // Smooth scroll for anchor links // ============================================ document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); const target = document.querySelector(this.getAttribute('href')); if (target) { target.scrollIntoView({ behavior: 'smooth', block: 'start' }); } }); }); // ============================================ // Parallax Doodles on Scroll // ============================================ const floatingDoodles = document.querySelectorAll('.doodle, .doodle-interactive'); window.addEventListener('scroll', () => { const scrollY = window.scrollY; floatingDoodles.forEach((doodle, i) => { const speed = (i % 3 + 1) * 0.05; doodle.style.transform = `translateY(${scrollY * speed}px)`; }); }); // ============================================ // Reveal Initial Elements // ============================================ setTimeout(() => { document.querySelectorAll('#hero .reveal').forEach((el, i) => { setTimeout(() => el.classList.add('active'), i * 100); }); }, 300); // ============================================ // Mouse Parallax for Hero Section // ============================================ const hero = document.getElementById('hero'); hero.addEventListener('mousemove', e => { const x = (e.clientX - window.innerWidth / 2) / 50; const y = (e.clientY - window.innerHeight / 2) / 50; floatingDoodles.forEach((doodle, i) => { const factor = (i + 1) * 0.3; doodle.style.transform = `translate(${x * factor}px, ${y * factor}px)`; }); }); // ============================================ // Easter Egg: Konami Code // ============================================ let konamiSequence = []; const konamiCode = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; document.addEventListener('keydown', e => { konamiSequence.push(e.keyCode); if (konamiSequence.length > konamiCode.length) { konamiSequence.shift(); } if (JSON.stringify(konamiSequence) === JSON.stringify(konamiCode)) { document.body.style.filter = 'invert(1)'; showToast('👻 You found the ghost mode!'); setTimeout(() => { document.body.style.filter = ''; }, 3000); } }); // ============================================ // Ripple effect on click // ============================================ document.addEventListener('click', e => { const ripple = document.createElement('div'); ripple.style.cssText = ` position: fixed; left: ${e.clientX}px; top: ${e.clientY}px; width: 0; height: 0; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); pointer-events: none; z-index: 9997; transform: translate(-50%, -50%); transition: all 0.6s ease-out; `; document.body.appendChild(ripple); requestAnimationFrame(() => { ripple.style.width = '100px'; ripple.style.height = '100px'; ripple.style.opacity = '0'; }); setTimeout(() => ripple.remove(), 600); }); // ============================================ // Typing animation for hero // ============================================ const heroSubtext = document.querySelector('#hero p'); if (heroSubtext) { const originalHTML = heroSubtext.innerHTML; heroSubtext.innerHTML = ''; heroSubtext.classList.add('active'); setTimeout(() => { let charIndex = 0; const tempDiv = document.createElement('div'); tempDiv.innerHTML = originalHTML; const plainText = tempDiv.textContent; function typeChar() { if (charIndex <= plainText.length) { heroSubtext.textContent = plainText.substring(0, charIndex); charIndex++; setTimeout(typeChar, 20 + Math.random() * 30); } else { heroSubtext.innerHTML = originalHTML; } } typeChar(); }, 800); } console.log('%c👻 Phantom Portfolio', 'font-size: 24px; font-weight: bold; color: white; background: #0a0a0a; padding: 10px 20px; border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;'); console.log('%cYou found the console! Try the Konami code ↑↑↓↓←→←→BA', 'color: #666; font-style: italic;');