npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vgerbot/weather-canvas

v0.1.0

Published

A lightweight, high-performance HTML5 Canvas library for rendering dynamic weather effects. Supports various weather conditions, day/night cycles, and adjustable intensities.

Readme

@vgerbot/weather-canvas

A lightweight, high-performance HTML5 Canvas library for rendering dynamic weather effects. Supports various weather conditions, day/night cycles, and adjustable intensities.

Previews

sunny day mode

sunny night mode

haze day mode

Features

  • Multiple Weather Types: Sunny, Cloudy, Overcast, Rainy, Snowy, Haze, Foggy, Thunderstorm.
  • Day & Night Modes: Automatic lighting adjustments for different times of day.
  • Adjustable Intensity: Control the severity of weather (Light, Moderate, Heavy).
  • Dynamic Wind: Adjustable wind speed affecting rain and snow direction.
  • Web Component Support: Drop-in <weather-canvas> element for easy integration.
  • High Performance: Optimized HTML5 Canvas rendering with requestAnimationFrame.
  • TypeScript Support: Fully typed for better development experience.
  • Zero Dependencies: (Runtime) Lightweight and standalone.

Installation

Install via npm:

npm install @vgerbot/weather-canvas

or yarn:

yarn add @vgerbot/weather-canvas

or pnpm:

pnpm add @vgerbot/weather-canvas

CDN

You can also use the library directly via CDN:

<script src="https://unpkg.com/@vgerbot/weather-canvas"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/@vgerbot/weather-canvas"></script>

Usage

1. As a Web Component (Recommended)

The easiest way to use Weather Canvas is as a custom element.

First, import the library to register the custom element:

import '@vgerbot/weather-canvas';

Then use it in your HTML:

<weather-canvas
    width="800"
    height="400"
    weather-type="rainy"
    time-mode="night"
    intensity="moderate"
    wind="2"
></weather-canvas>

Attributes

| Attribute | Type | Default | Description | | :------------- | :------- | :--------- | :-------------------------------------------------------------------------- | | weather-type | String | sunny | sunny, cloudy, overcast, rainy, snowy, haze, foggy, thunderstorm | | time-mode | String | day | day, night | | intensity | String | moderate | light, moderate, heavy | | width | Number | 700 | Canvas width in pixels | | height | Number | 400 | Canvas height in pixels | | wind | Number | 0 | Wind speed (negative for left, positive for right) |

Methods

  • start(): Start the animation.
  • stop(): Stop the animation.
  • registerCustomWeather(name: string, config: CustomWeatherConfig): Register a new custom weather type.

2. Programmatic Usage (Vanilla JS / TypeScript)

For more control, you can use the WeatherCanvasRenderer directly.

import { WeatherCanvasRenderer, WeatherIntensity } from '@vgerbot/weather-canvas';

// 1. Get your canvas element
const canvas = document.getElementById('my-canvas');

// 2. Initialize the renderer
const renderer = new WeatherCanvasRenderer(canvas);

// 3. Configure and Start
// render(weatherType, timeMode, intensity)
renderer.render('rainy', 'night', 'heavy');
renderer.start();

// ... later ...

// Update settings dynamically
renderer.setWeatherType('sunny');
renderer.setMode('day');
renderer.setWind(5.0); // Strong wind to the right

// Stop animation
// renderer.stop();

Custom Weather Types

You can register your own custom weather types with specific configurations for background colors and weather elements.

1. Using Web Component

const weatherCanvas = document.querySelector('weather-canvas');

weatherCanvas.registerCustomWeather('mars-storm', {
    background: {
        day: ['#ff4d4d', '#b30000'],   // Reddish sky
        night: ['#4d0000', '#1a0000']
    },
    elements: [
        {
            type: 'fog',
            options: {
                count: 20,
                color: '255, 100, 100' // Reddish fog
            }
        },
        {
            type: 'snow', // Using snow particles to simulate dust
            options: {
                count: 200,
                speed: 1.5,
                opacity: 0.8
            }
        }
    ]
});

// Use the new weather type
weatherCanvas.setAttribute('weather-type', 'mars-storm');

2. Using Renderer

renderer.registerWeather('mars-storm', {
    background: {
        day: ['#ff4d4d', '#b30000'],
        night: ['#4d0000', '#1a0000']
    },
    elements: [
        {
            type: 'stars',
            options: { count: 100 },
            modes: ['night'] // Only show stars at night
        },
        {
            type: 'cloud',
            options: {
                count: 5,
                widthRange: [100, 200],
                heightRange: [60, 100],
                speedRange: [0.5, 1],
                opacityRange: [0.4, 0.8],
                yRange: [0, 0.5]
            }
        }
    ]
});

renderer.setWeatherType('mars-storm');

Configuration Object (CustomWeatherConfig)

interface CustomWeatherConfig {
    background: {
        day: [string, string];   // Gradient colors [top, bottom]
        night: [string, string];
    };
    elements: Array<{
        type: 'sun' | 'moon' | 'stars' | 'shooting-stars' | 'cloud' | 'rain' | 'snow' | 'fog' | 'lightning' | 'background';
        options?: MoonConfig | StarsConfig | ShootingStarsConfig | CloudConfig | RainConfig | SnowConfig | FogConfig | lightningConfig | BackgroundConfig; // Specific options for each element
        modes?: ('day' | 'night')[]; // Optional: restrict to specific time modes
    }>;
}

API Reference

WeatherCanvasRenderer

Methods

  • constructor(canvas: HTMLCanvasElement): Creates a new renderer instance.
  • render(weather: WeatherType, mode: TimeMode, intensity: WeatherIntensity): Sets up the initial weather state.
  • start(): Starts the animation loop.
  • stop(): Stops the animation loop.
  • resize(width: number, height: number): Resizes the internal canvas dimensions.
  • setWeatherType(type: WeatherType): Changes the weather type dynamically.
  • setMode(mode: TimeMode): Changes between 'day' and 'night'.
  • setIntensity(intensity: WeatherIntensity): Changes weather intensity.
  • setWind(speed: number): Sets wind speed and direction.
  • registerWeather(name: string, config: CustomWeatherConfig): Registers a custom weather configuration.

Types

WeatherType

'sunny' | 'cloudy' | 'overcast' | 'rainy' | 'snowy' | 'haze' | 'foggy' | 'thunderstorm'

TimeMode

'day' | 'night'

WeatherIntensity

'light' | 'moderate' | 'heavy'

Development

  1. Clone the repository:

    git clone https://github.com/vgerbot-libraries/weather-canvas.git
  2. Install dependencies:

    pnpm install
  3. Run the development server (with examples):

    pnpm dev

License

MIT © ChienHsinYang