|
| 1 | +import { Component, ElementRef, ViewChild } from '@angular/core'; |
| 2 | +import { gsap } from 'gsap'; |
| 3 | + |
| 4 | +@Component({ |
| 5 | + selector: 'app-logo', |
| 6 | + imports: [], |
| 7 | + templateUrl: './logo.html', |
| 8 | + styleUrl: './logo.css' |
| 9 | +}) |
| 10 | +export class Logo { |
| 11 | + @ViewChild('svg', { static: false }) svg!: ElementRef; |
| 12 | + |
| 13 | + ngAfterViewInit(): void { |
| 14 | + if (!this.svg) { |
| 15 | + console.error('SVG ViewChild not found'); |
| 16 | + return; |
| 17 | + } |
| 18 | + |
| 19 | + const paths: NodeListOf<SVGPathElement> = this.svg.nativeElement.querySelectorAll('path'); |
| 20 | + |
| 21 | + // Initial appear animation for each path sequentially |
| 22 | + paths.forEach((path, i) => { |
| 23 | + gsap.set(path, { |
| 24 | + opacity: 0, |
| 25 | + scale: 1, |
| 26 | + x: 0, |
| 27 | + y: 0, |
| 28 | + scaleX: 1, |
| 29 | + scaleY: 1, |
| 30 | + transformOrigin: 'center center', |
| 31 | + filter: 'drop-shadow(0 0 0px #ffd700)' |
| 32 | + }); |
| 33 | + |
| 34 | + gsap.to(path, { |
| 35 | + opacity: 1, |
| 36 | + duration: 0.5, |
| 37 | + delay: i * 0.2, |
| 38 | + ease: 'power3.out' |
| 39 | + }); |
| 40 | + }); |
| 41 | + |
| 42 | + // Mousemove scatter + random flip effect |
| 43 | + window.addEventListener('mousemove', (e) => { |
| 44 | + const mouseX = e.clientX; |
| 45 | + const mouseY = e.clientY; |
| 46 | + |
| 47 | + paths.forEach((path) => { |
| 48 | + const bbox = path.getBoundingClientRect(); |
| 49 | + const cx = bbox.left + bbox.width / 2; |
| 50 | + const cy = bbox.top + bbox.height / 2; |
| 51 | + |
| 52 | + const dx = mouseX - cx; |
| 53 | + const dy = mouseY - cy; |
| 54 | + const distance = Math.sqrt(dx * dx + dy * dy); |
| 55 | + |
| 56 | + const maxDist = 150; |
| 57 | + const ratio = Math.max(0, 1 - distance / maxDist); |
| 58 | + |
| 59 | + if (ratio > 0) { |
| 60 | + // बिखरना और घुमाना |
| 61 | + const angle = Math.random() * Math.PI * 2; |
| 62 | + const scatterX = Math.cos(angle) * ratio * 20; |
| 63 | + const scatterY = Math.sin(angle) * ratio * 20; |
| 64 | + |
| 65 | + // उल्टा घुमाना: आड़ा या सीधा |
| 66 | + const flipHorizontally = Math.random() > 0.5; |
| 67 | + const flipValue = ratio > 0.5 ? -1 : 1; |
| 68 | + |
| 69 | + const flipProps = flipHorizontally |
| 70 | + ? { scaleX: flipValue, scaleY: 1 } |
| 71 | + : { scaleX: 1, scaleY: flipValue }; |
| 72 | + |
| 73 | + gsap.to(path, { |
| 74 | + x: scatterX, |
| 75 | + y: scatterY, |
| 76 | + scale: 1 + ratio * 0.1, |
| 77 | + ...flipProps, |
| 78 | + filter: `drop-shadow(0 0 ${10 + ratio * 20}px #ffd700)`, |
| 79 | + duration: 0.4, |
| 80 | + ease: 'power2.out' |
| 81 | + }); |
| 82 | + } else { |
| 83 | + // माउस के दूर जाने पर वापस असली जगह पर ले जाना |
| 84 | + gsap.to(path, { |
| 85 | + x: 0, |
| 86 | + y: 0, |
| 87 | + scale: 1, |
| 88 | + scaleX: 1, |
| 89 | + scaleY: 1, |
| 90 | + filter: 'drop-shadow(0 0 0px #ffd700)', |
| 91 | + duration: 0.6, |
| 92 | + ease: 'power2.out' |
| 93 | + }); |
| 94 | + } |
| 95 | + }); |
| 96 | + }); |
| 97 | + } |
| 98 | +} |
0 commit comments