// Create hail and lightning animation function createHailAnimation() { const container = document.createElement('div'); container.className = 'hail-container'; document.body.appendChild(container); // Create lightning effect const lightning = document.createElement('div'); lightning.className = 'lightning'; container.appendChild(lightning); // Random lightning flashes function triggerLightning() { const duration = 2 + Math.random() * 3; const delay = Math.random() * 15; lightning.style.animation = `lightning ${duration}s ${delay}s linear`; setTimeout(() => { lightning.style.animation = 'none'; setTimeout(triggerLightning, Math.random() * 10000 + 5000); // Next flash in 5-15 seconds }, (duration + delay) * 1000); } // Start lightning triggerLightning(); // Create car container with lightning illumination effect const carContainer = document.createElement('div'); carContainer.className = 'car-container'; carContainer.style.filter = 'brightness(0.7)'; carContainer.style.transition = 'filter 0.3s ease'; // Sync car brightness with lightning lightning.addEventListener('animationstart', () => { carContainer.style.filter = 'brightness(1.5)'; }); lightning.addEventListener('animationend', () => { carContainer.style.filter = 'brightness(0.7)'; }); const car = document.createElement('div'); car.className = 'car'; carContainer.appendChild(car); document.body.appendChild(carContainer); // Add rain effect function createRain() { const rain = document.createElement('div'); rain.className = 'rain'; container.appendChild(rain); for (let i = 0; i < 100; i++) { const drop = document.createElement('div'); drop.className = 'rain-drop'; drop.style.left = `${Math.random() * 100}%`; drop.style.animationDuration = `${0.5 + Math.random() * 0.5}s`; drop.style.animationDelay = `${Math.random() * 2}s`; rain.appendChild(drop); } } createRain(); // Generate hail function generateHail() { const hail = document.createElement('div'); hail.className = 'hail'; // Random position const left = Math.random() * 100; const duration = 2 + Math.random() * 3; const delay = Math.random() * 5; const size = 4 + Math.random() * 4; hail.style.left = `${left}%`; hail.style.width = `${size}px`; hail.style.height = `${size}px`; hail.style.animationDuration = `${duration}s`; hail.style.animationDelay = `${delay}s`; container.appendChild(hail); // Create impact effect when hail hits car setTimeout(() => { if (left > 35 && left < 65) { // Only show impacts on car const impact = document.createElement('div'); impact.className = 'hail-impact'; impact.style.left = `${Math.random() * 80 + 10}%`; impact.style.top = `${Math.random() * 50 + 20}%`; car.appendChild(impact); setTimeout(() => { impact.remove(); }, 300); } }, duration * 1000 * (1 - (50 / window.innerHeight))); // Remove hail after animation setTimeout(() => { hail.remove(); }, duration * 1000); } // Initial hail for (let i = 0; i < 50; i++) { generateHail(); } // Continuous hail generation setInterval(generateHail, 100); } document.addEventListener('DOMContentLoaded', function() { // Create hail animation createHailAnimation(); // Weather API functions const API_KEY = 'YOUR_OPENWEATHERMAP_API_KEY'; // Replace with your actual API key const weatherContainer = document.getElementById('weatherContainer'); const weatherSearchBtn = document.getElementById('weatherSearchBtn'); const locationInput = document.getElementById('locationInput'); async function fetchWeather(location) { try { const response = await fetch(`https://api.openweathermap.org/data/2.5/forecast?q=${location}&appid=${API_KEY}&units=imperial`); const data = await response.json(); if (data.cod !== "200") throw new Error(data.message); // Filter to get one forecast per day (every 8th item in the array) const dailyForecasts = data.list.filter((item, index) => index % 8 === 0).slice(0, 3); weatherContainer.innerHTML = dailyForecasts.map(forecast => { const date = new Date(forecast.dt * 1000); const iconUrl = `https://openweathermap.org/img/wn/${forecast.weather[0].icon}@2x.png`; return `
${error.message}