File size: 4,058 Bytes
1838d8f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
class NumberAnimationManager {
    constructor() {
        this.container = document.getElementById('animation-container');
        this.currentAnimation = null;
        this.isLooping = false;
        this.initializeControls();
    }

    initializeControls() {
        const playBtn = document.getElementById('play-btn');
        const loopToggle = document.getElementById('loop-toggle');
        const animationSelect = document.getElementById('animation-select');
        const numberSelect = document.getElementById('number-select');

        playBtn.addEventListener('click', () => {
            this.playAnimation(
                numberSelect.value,
                animationSelect.value
            );
        });

        loopToggle.addEventListener('click', () => {
            this.isLooping = !this.isLooping;
            loopToggle.textContent = `Loop: ${this.isLooping ? 'On' : 'Off'}`;
            if (this.isLooping && this.currentAnimation) {
                this.startLoop();
            }
        });
    }

    playAnimation(number, animationType) {
        this.clearContainer();
        
        const numberElement = this.createNumberElement(number);
        this.container.appendChild(numberElement);

        if (animationType === 'smoke') {
            this.createParticles();
        }

        // Add animation class
        setTimeout(() => {
            numberElement.classList.add(this.getAnimationClass(animationType));
        }, 100);

        this.currentAnimation = { number, animationType };

        if (this.isLooping) {
            this.startLoop();
        }
    }

    createNumberElement(number) {
        const div = document.createElement('div');
        div.className = 'cinematic-number';
        div.textContent = number;
        div.setAttribute('data-number', number);
        return div;
    }

    createParticles() {
        const particlesContainer = document.createElement('div');
        particlesContainer.className = 'particles';
        
        for (let i = 0; i < 50; i++) {
            const particle = document.createElement('div');
            particle.className = 'particle';
            
            const angle = Math.random() * Math.PI * 2;
            const distance = 100 + Math.random() * 200;
            const tx = Math.cos(angle) * distance;
            const ty = Math.sin(angle) * distance;
            
            particle.style.setProperty('--tx', `${tx}px`);
            particle.style.setProperty('--ty', `${ty}px`);
            particle.style.left = '50%';
            particle.style.top = '50%';
            particle.style.animationDelay = `${Math.random() * 1}s`;
            
            particlesContainer.appendChild(particle);
        }
        
        this.container.appendChild(particlesContainer);
        
        // Remove particles after animation
        setTimeout(() => {
            particlesContainer.remove();
        }, 2000);
    }

    getAnimationClass(animationType) {
        const animationClasses = {
            'zoom': 'zoom-in',
            'bounce': 'bounce-in',
            'smoke': 'smoke-reveal',
            'glitch': 'glitch-flicker',
            'pulse': 'energy-pulse'
        };
        
        return animationClasses[animationType] || 'zoom-in';
    }

    clearContainer() {
        this.container.innerHTML = '';
    }

    startLoop() {
        if (!this.isLooping || !this.currentAnimation) return;

        const { number, animationType } = this.currentAnimation;
        const durations = {
            'zoom': 3000,
            'bounce': 1500,
            'smoke': 4000,
            'glitch': 2500,
            'pulse': 3000
        };

        setInterval(() => {
            this.playAnimation(number, animationType);
        }, durations[animationType] || 3000);
    }
}

// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
    new NumberAnimationManager();
    
    // Auto-play first animation
    setTimeout(() => {
        document.getElementById('play-btn').click();
    }, 500);
});