File size: 11,526 Bytes
88a780a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Moonlit Owl Animation</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/gsap@3.11.4/dist/gsap.min.js"></script>
    <style>
        body {
            margin: 0;
            overflow: hidden;
            background-color: #0a0a1a;
        }
        canvas {
            display: block;
        }
        #sound-btn {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);
            background: rgba(255, 255, 255, 0.2);
            border: 2px solid white;
            color: white;
            padding: 10px 20px;
            border-radius: 30px;
            cursor: pointer;
            font-family: 'Arial', sans-serif;
            font-weight: bold;
            backdrop-filter: blur(5px);
            transition: all 0.3s ease;
        }
        #sound-btn:hover {
            background: rgba(255, 255, 255, 0.3);
            transform: translateX(-50%) scale(1.05);
        }
        #instructions {
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
            color: white;
            text-align: center;
            font-family: 'Arial', sans-serif;
            background: rgba(0, 0, 0, 0.5);
            padding: 10px 20px;
            border-radius: 10px;
            font-size: 14px;
        }
        .moon {
            position: absolute;
            top: 50px;
            right: 50px;
            width: 80px;
            height: 80px;
            background: radial-gradient(circle, #f5f3ce 0%, #e8e6b5 70%);
            border-radius: 50%;
            box-shadow: 0 0 40px 15px rgba(245, 243, 206, 0.4);
            z-index: 1;
        }
    </style>
</head>
<body>
    <div class="moon"></div>
    <div id="instructions">Click the owl to hear it hoot!</div>
    <button id="sound-btn">Toggle Sound</button>
    
    <script>
        // Initialize Three.js scene
        const scene = new THREE.Scene();
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        const renderer = new THREE.WebGLRenderer({ antialias: true });
        renderer.setSize(window.innerWidth, window.innerHeight);
        renderer.setClearColor(0x0a0a1a);
        document.body.appendChild(renderer.domElement);

        // Add stars
        const starsGeometry = new THREE.BufferGeometry();
        const starsMaterial = new THREE.PointsMaterial({
            color: 0xffffff,
            size: 0.1,
            transparent: true,
            opacity: 0.8
        });

        const starsVertices = [];
        for (let i = 0; i < 1000; i++) {
            const x = (Math.random() - 0.5) * 2000;
            const y = (Math.random() - 0.5) * 2000;
            const z = (Math.random() - 0.5) * 2000;
            starsVertices.push(x, y, z);
        }

        starsGeometry.setAttribute('position', new THREE.Float32BufferAttribute(starsVertices, 3));
        const stars = new THREE.Points(starsGeometry, starsMaterial);
        scene.add(stars);

        // Create owl
        const owlGroup = new THREE.Group();
        scene.add(owlGroup);

        // Owl body
        const bodyGeometry = new THREE.SphereGeometry(1, 32, 32);
        const bodyMaterial = new THREE.MeshPhongMaterial({ 
            color: 0x5a4a3a,
            shininess: 30
        });
        const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
        owlGroup.add(body);

        // Owl head
        const headGeometry = new THREE.SphereGeometry(0.8, 32, 32);
        const headMaterial = new THREE.MeshPhongMaterial({ 
            color: 0x5a4a3a,
            shininess: 30
        });
        const head = new THREE.Mesh(headGeometry, headMaterial);
        head.position.y = 0.8;
        owlGroup.add(head);

        // Owl eyes
        const eyeGeometry = new THREE.SphereGeometry(0.2, 32, 32);
        const eyeMaterial = new THREE.MeshPhongMaterial({ color: 0xffffff });
        
        const leftEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
        leftEye.position.set(-0.3, 0.9, 0.6);
        owlGroup.add(leftEye);
        
        const rightEye = new THREE.Mesh(eyeGeometry, eyeMaterial);
        rightEye.position.set(0.3, 0.9, 0.6);
        owlGroup.add(rightEye);

        // Owl pupils
        const pupilGeometry = new THREE.SphereGeometry(0.1, 32, 32);
        const pupilMaterial = new THREE.MeshPhongMaterial({ color: 0x000000 });
        
        const leftPupil = new THREE.Mesh(pupilGeometry, pupilMaterial);
        leftPupil.position.set(-0.3, 0.9, 0.8);
        owlGroup.add(leftPupil);
        
        const rightPupil = new THREE.Mesh(pupilGeometry, pupilMaterial);
        rightPupil.position.set(0.3, 0.9, 0.8);
        owlGroup.add(rightPupil);

        // Owl beak
        const beakGeometry = new THREE.ConeGeometry(0.1, 0.3, 32);
        const beakMaterial = new THREE.MeshPhongMaterial({ color: 0xf5a742 });
        const beak = new THREE.Mesh(beakGeometry, beakMaterial);
        beak.position.set(0, 0.7, 0.8);
        beak.rotation.x = Math.PI / 2;
        owlGroup.add(beak);

        // Owl wings
        const wingGeometry = new THREE.SphereGeometry(0.8, 32, 32);
        wingGeometry.scale(1, 0.2, 0.5);
        
        const leftWing = new THREE.Mesh(wingGeometry, bodyMaterial);
        leftWing.position.set(-1, 0, 0);
        owlGroup.add(leftWing);
        
        const rightWing = new THREE.Mesh(wingGeometry, bodyMaterial);
        rightWing.position.set(1, 0, 0);
        owlGroup.add(rightWing);

        // Add lighting
        const moonLight = new THREE.PointLight(0xf5f3ce, 1, 100);
        moonLight.position.set(10, 10, 10);
        scene.add(moonLight);

        const ambientLight = new THREE.AmbientLight(0x404040);
        scene.add(ambientLight);

        // Position camera
        camera.position.z = 5;

        // Animation variables
        let wingFlapSpeed = 0.1;
        let owlPosition = { x: 0, y: 0, z: 0 };
        let targetPosition = { x: 0, y: 0, z: 0 };
        let flightPath = [];
        let currentPathIndex = 0;

        // Generate random flight path
        for (let i = 0; i < 10; i++) {
            flightPath.push({
                x: (Math.random() - 0.5) * 10,
                y: (Math.random() - 0.5) * 5,
                z: (Math.random() - 0.5) * 10
            });
        }

        // Sound setup
        let audioContext;
        let gainNode;
        let soundEnabled = true;
        const soundBtn = document.getElementById('sound-btn');

        function initAudio() {
            audioContext = new (window.AudioContext || window.webkitAudioContext)();
            gainNode = audioContext.createGain();
            gainNode.gain.value = 0.5;
            gainNode.connect(audioContext.destination);
        }

        function playHoot() {
            if (!soundEnabled || !audioContext) return;
            
            const oscillator = audioContext.createOscillator();
            const gain = audioContext.createGain();
            
            oscillator.type = 'sine';
            oscillator.frequency.setValueAtTime(300, audioContext.currentTime);
            oscillator.frequency.exponentialRampToValueAtTime(200, audioContext.currentTime + 0.5);
            
            gain.gain.setValueAtTime(0.3, audioContext.currentTime);
            gain.gain.exponentialRampToValueAtTime(0.001, audioContext.currentTime + 0.5);
            
            oscillator.connect(gain);
            gain.connect(gainNode);
            
            oscillator.start();
            oscillator.stop(audioContext.currentTime + 0.5);
        }

        // Toggle sound
        soundBtn.addEventListener('click', () => {
            soundEnabled = !soundEnabled;
            soundBtn.textContent = soundEnabled ? 'Sound: ON' : 'Sound: OFF';
        });

        // Owl click event
        renderer.domElement.addEventListener('click', (event) => {
            const mouse = new THREE.Vector2(
                (event.clientX / window.innerWidth) * 2 - 1,
                -(event.clientY / window.innerHeight) * 2 + 1
            );
            
            const raycaster = new THREE.Raycaster();
            raycaster.setFromCamera(mouse, camera);
            
            const intersects = raycaster.intersectObject(owlGroup, true);
            
            if (intersects.length > 0) {
                playHoot();
                
                // Change flight path when clicked
                currentPathIndex = (currentPathIndex + 1) % flightPath.length;
                targetPosition = flightPath[currentPathIndex];
                
                // Increase wing flap speed temporarily
                wingFlapSpeed = 0.3;
                setTimeout(() => { wingFlapSpeed = 0.1; }, 1000);
            }
        });

        // Handle window resize
        window.addEventListener('resize', () => {
            camera.aspect = window.innerWidth / window.innerHeight;
            camera.updateProjectionMatrix();
            renderer.setSize(window.innerWidth, window.innerHeight);
        });

        // Animation loop
        function animate() {
            requestAnimationFrame(animate);
            
            // Update owl position towards target
            owlPosition.x += (targetPosition.x - owlPosition.x) * 0.01;
            owlPosition.y += (targetPosition.y - owlPosition.y) * 0.01;
            owlPosition.z += (targetPosition.z - owlPosition.z) * 0.01;
            
            owlGroup.position.set(owlPosition.x, owlPosition.y, owlPosition.z);
            
            // Make owl look forward in its direction of movement
            if (Math.abs(targetPosition.x - owlPosition.x) > 0.1 || 
                Math.abs(targetPosition.z - owlPosition.z) > 0.1) {
                const angle = Math.atan2(
                    targetPosition.x - owlPosition.x, 
                    targetPosition.z - owlPosition.z
                );
                owlGroup.rotation.y = angle;
            }
            
            // Wing flapping animation
            const time = Date.now() * 0.001;
            leftWing.rotation.z = Math.sin(time * 5 * wingFlapSpeed) * 0.5;
            rightWing.rotation.z = -Math.sin(time * 5 * wingFlapSpeed) * 0.5;
            
            // Rotate stars for parallax effect
            stars.rotation.y += 0.0001;
            
            renderer.render(scene, camera);
        }

        // Initialize audio and start animation
        initAudio();
        animate();
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=aicoding101/j-j" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>