Dynamic Sky

Transform your web experience with breathtaking, real-time sky renders that evolve throughout the day. From golden sunrises to star-studded nights—bring the atmosphere to life.

Scroll to explore

Key Features

Everything you need for stunning sky backgrounds

🌅 Realistic Sky Rendering

Physically-based atmospheric scattering using single-scattering approximation for authentic sky colors throughout the day.

Animated Starfield

Multi-layer parallax starfield with breathing animation that automatically appears at night and fades during twilight. Note: Stars are decorative and not accurate to real astronomical positions. They are randomly generated for visual effect and do not represent real constellations or star positions.

🌍 Location-Aware

Auto-detects location via IP geolocation or set custom coordinates for accurate sun position calculations.

🔄 Time-Based Control

Connect any slider (linear, circular, or custom) to control time and see the sky change in real-time.

📱 Mobile Optimized

Automatically adjusts star density and rendering for optimal performance on mobile devices.

🎨 Flexible Integration

Works as full-page background or contained element. Easy to integrate into any design.

🔓 Full Open Source

Completely open source and free to use. Explore on GitHub →

Quick Start

Get started in minutes with just a few lines of code

<!-- Include the library -->
<script src="dynamic-sky.js"></script>

<!-- Add containers for sky and stars -->
<div id="background-sky"></div>
<div id="stars-container"></div>

<script>
  // Create a new DynamicSky instance
  const sky = new DynamicSky();
  // Initialize (auto-detects location via IP geolocation)
  sky.init();
</script>
  • No CSS files needed - styles are automatically injected
  • Works as full-page background or contained element
  • Auto-detects location or set custom coordinates
  • Connect any slider type (linear, circular, custom)
  • Mobile optimized with automatic performance tuning

Use Case Examples

See DynamicSky in action across different integration scenarios

🎮 Immersive Background

Create immersive experiences with full-page sky backgrounds. Perfect for landing pages, portfolios, and creative projects.

The sky you see behind this page is a live example! Use the slider below to control it.

Background Sky Time 12:00 AM
12:00 AM 12:00 AM
Code
<div id="background-sky"></div>
<div id="stars-container"></div>

<script>
  const sky = new DynamicSky({
    skyContainer: '#background-sky',
    starsContainer: '#stars-container'
  });
  sky.init().then(() => {
    const slider = document.getElementById('time-slider');
    slider.addEventListener('input', () => {
      const minutes = parseInt(slider.value);
      sky.updateSky(sky.minutesToDate(minutes));
    });
  });
</script>
🌤️ Weather Application

Show current sky conditions matching the time of day. Perfect for weather apps that want to display realistic sky backgrounds.

Time of Day 12:00 AM
12:00 AM 12:00 AM
Current Time Sky
Code
<div id="weather-sky"></div>
<div id="weather-stars"></div>
<input type="range" id="time-slider" min="0" max="1440">

<script>
  const sky = new DynamicSky({
    skyContainer: '#weather-sky',
    starsContainer: '#weather-stars'
  });
  sky.init().then(() => {
    const slider = document.getElementById('time-slider');
    slider.addEventListener('input', () => {
      const minutes = parseInt(slider.value);
      sky.updateSky(sky.minutesToDate(minutes));
    });
  });
</script>
📊 Dashboard Widget (Programmatic Control)

Compact sky preview for dashboards and admin panels. This example demonstrates programmatic control - the slider moves automatically to show how you can change the sky programmatically without user interaction.

🔄 Slider moves automatically - demonstrating programmatic sky control

Time (Auto-Controlled) 12:00 AM
12:00 AM 12:00 AM
Auto-Updating Dashboard Widget
Code
<script>
  const sky = new DynamicSky({
    skyContainer: '#dashboard-sky',
    starsContainer: '#dashboard-stars'
  });
  sky.init().then(() => {
    let currentMinutes = 0;
    setInterval(() => {
      currentMinutes = (currentMinutes + 1) % 1440;
      sky.updateSky(sky.minutesToDate(currentMinutes));
    }, 1000); // Update every second
  });
</script>
✈️ Travel & Time Zones

Compare sky conditions across different locations and time zones. Great for travel apps showing destination weather.

Local Time 12:00 AM
12:00 AM 12:00 AM
New York - 12:00 AM
Code
<script>
  const sky = new DynamicSky({
    skyContainer: '#travel-sky',
    starsContainer: '#travel-stars',
    latitude: 40.7128,  // New York
    longitude: -74.0060
  });
  sky.init().then(() => {
    // Change location when button clicked
    document.querySelectorAll('.location-btn').forEach(btn => {
      btn.addEventListener('click', () => {
        const loc = locations[btn.dataset.location];
        sky.setLocation(loc.lat, loc.lng);
        sky.updateSky(sky.minutesToDate(slider.value));
      });
    });
  });
</script>
🔄 Auto-Updating Sky

Sky that automatically updates to match the current time. Perfect for dashboards or apps that want to show real-time sky conditions without manual controls.

⏱️ Updates automatically every minute

Live Time: --:--
Code
<script>
  const sky = new DynamicSky({
    skyContainer: '#auto-sky',
    starsContainer: '#auto-stars'
  });
  sky.init().then(() => {
    function updateToCurrentTime() {
      const now = new Date();
      sky.updateSky(now);
    }
    updateToCurrentTime();
    setInterval(updateToCurrentTime, 60000); // Update every minute
  });
</script>
🛍️ Product Showcase Card

Use sky as a background element in product cards or hero sections. Shows how DynamicSky can enhance UI components beyond full-page backgrounds.

Sky Time 12:00 AM
12:00 AM 12:00 AM

Premium Product

Beautiful sky background enhances your product presentation

Code
<div style="position: relative;">
  <div id="product-sky"></div>
  <div id="product-stars"></div>
  <div style="position: absolute; bottom: 0;">
    <h3>Product Title</h3>
  </div>
</div>

<script>
  const sky = new DynamicSky({
    skyContainer: '#product-sky',
    starsContainer: '#product-stars'
  });
  sky.init();
</script>
Time Comparison

Compare how the sky looks at different times of day. Useful for showing time-based variations in a single view.

Morning
Noon
Evening

Multiple sky instances showing different times simultaneously

Code
<script>
  // Create multiple sky instances
  const morningSky = new DynamicSky({
    skyContainer: '#morning-sky',
    starsContainer: '#morning-stars'
  });
  const noonSky = new DynamicSky({
    skyContainer: '#noon-sky',
    starsContainer: '#noon-stars'
  });
  const eveningSky = new DynamicSky({
    skyContainer: '#evening-sky',
    starsContainer: '#evening-stars'
  });
  
  Promise.all([morningSky.init(), noonSky.init(), eveningSky.init()]).then(() => {
    morningSky.updateSky(morningSky.minutesToDate(360));  // 6 AM
    noonSky.updateSky(noonSky.minutesToDate(720));        // 12 PM
    eveningSky.updateSky(eveningSky.minutesToDate(1080));  // 6 PM
  });
</script>
🌍 Location Comparison

Compare sky conditions across multiple locations simultaneously. Great for travel apps or weather dashboards showing conditions in different cities.

San Francisco
37.77°N, 122.41°W
New York
40.71°N, 74.01°W
Tokyo
35.68°N, 139.69°E
London
51.51°N, 0.13°W
Code
<script>
  const locations = [
    { lat: 37.7749, lng: -122.4194 },  // San Francisco
    { lat: 40.7128, lng: -74.0060 },   // New York
    { lat: 35.6762, lng: 139.6503 },   // Tokyo
    { lat: 51.5074, lng: -0.1278 }     // London
  ];
  
  const skies = locations.map((loc, i) => {
    return new DynamicSky({
      skyContainer: `#compare-${i+1}-sky`,
      starsContainer: `#compare-${i+1}-stars`,
      latitude: loc.lat,
      longitude: loc.lng
    });
  });
  
  Promise.all(skies.map(sky => sky.init())).then(() => {
    const date = skies[0].minutesToDate(slider.value);
    skies.forEach(sky => sky.updateSky(date));
  });
</script>
Compare Time 12:00 AM
12:00 AM 12:00 AM

Advanced Usage

Explore advanced features and programmatic control

⚙️ Custom Container and Location

Initialize with custom containers and specific coordinates for precise control over sky placement and location.

Code
<!-- Custom containers -->
<div id="my-sky"></div>
<div id="my-stars"></div>

<script>
  // Initialize with custom containers and location
  const sky = new DynamicSky({
    skyContainer: '#my-sky',
    starsContainer: '#my-stars',
    latitude: 40.7128,  // New York
    longitude: -74.0060
  });
  sky.init();
</script>
🔄 Programmatic Control

Change the sky programmatically without user interaction. Perfect for automated updates or animations.

Code
<script>
  const sky = new DynamicSky();
  sky.init().then(() => {
    // Update sky to specific time
    const specificDate = new Date('2024-01-15T14:30:00');
    sky.updateSky(specificDate);
    
    // Or use minutes (0-1440)
    const minutes = 720; // 12:00 PM
    sky.updateSky(sky.minutesToDate(minutes));
  });
</script>
🌍 Changing Location Dynamically

Update the location after initialization to show sky conditions at different places.

Code
<script>
  const sky = new DynamicSky();
  sky.init().then(() => {
    // Change location to Tokyo
    sky.setLocation(35.6762, 139.6503);
    
    // Update sky with current time at new location
    sky.updateSky(new Date());
  });
</script>
⏱️ Auto-Updating Sky

Keep the sky synchronized with the current time automatically.

Code
<script>
  const sky = new DynamicSky();
  sky.init().then(() => {
    // Function to update sky to current time
    function updateToCurrentTime() {
      const now = new Date();
      sky.updateSky(now);
    }
    
    // Update immediately
    updateToCurrentTime();
    
    // Update every minute
    setInterval(updateToCurrentTime, 60000);
  });
</script>