Map Snow
terrae/snowFreeComponent
Falling snowflakes effect with gentle drift and wind.
Install it
npx shadcn@latest add https://www.terrae.dev/snow.jsonSource
1"use client"23import { useEffect, useId, useRef, useState, useCallback } from "react"4import { createPortal } from "react-dom"5import { useMap } from "./hooks"67type RgbColor = {8 red: number9 green: number10 blue: number11}1213type SnowParticle = {14 x: number15 y: number16 size: number17 speed: number18 opacity: number19 wobble: number20 wobbleSpeed: number21 wobbleAmount: number22}2324type SnowControl = {25 start: () => void26 stop: () => void27 setIntensity: (intensity: number) => void28 isActive: boolean29}3031type SnowOverlayProps = {32 intensity: number33 particleCount: number34 color: string35 windSpeed: number36 windDirection: number37 fallSpeed: number38 isActive: boolean39 onControlReady: (control: SnowControl) => void40}4142type MapSnowProps = {43 id?: string44 intensity?: number45 particleCount?: number46 color?: string47 windSpeed?: number48 windDirection?: number49 fallSpeed?: number50 autoStart?: boolean51}5253const DEFAULT_INTENSITY = 154const DEFAULT_PARTICLE_COUNT = 15055const DEFAULT_COLOR = "#ffffff"56const DEFAULT_WIND_SPEED = 0.557const DEFAULT_WIND_DIRECTION = 058const DEFAULT_FALL_SPEED = 15960const MIN_INTENSITY = 0.161const MAX_INTENSITY = 362const PARTICLE_SPAWN_OFFSET = 10063const PARTICLE_MIN_SIZE = 264const PARTICLE_SIZE_RANGE = 465const PARTICLE_MIN_SPEED = 0.566const PARTICLE_SPEED_RANGE = 1.567const PARTICLE_MIN_OPACITY = 0.468const PARTICLE_OPACITY_RANGE = 0.669const PARTICLE_MIN_WOBBLE_SPEED = 0.0170const PARTICLE_WOBBLE_SPEED_RANGE = 0.0371const PARTICLE_MIN_WOBBLE_AMOUNT = 0.572const PARTICLE_WOBBLE_AMOUNT_RANGE = 1.573const BOUNDS_PADDING = 2074const DEGREES_TO_RADIANS = Math.PI / 18075const WOBBLE_DRIFT_FACTOR = 0.376const GRADIENT_MID_OPACITY_FACTOR = 0.677const CONTROL_UPDATE_INTERVAL = 1007879const snowControls = new Map<string, SnowControl>()8081const hexToRgb = (hex: string): RgbColor => {82 const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)8384 if (!result) {85 return { red: 255, green: 255, blue: 255 }86 }8788 return {89 red: parseInt(result[1], 16),90 green: parseInt(result[2], 16),91 blue: parseInt(result[3], 16),92 }93}9495const createParticle = (canvasWidth: number, canvasHeight: number, intensity: number): SnowParticle => {96 return {97 x: Math.random() * canvasWidth,98 y: -BOUNDS_PADDING - Math.random() * PARTICLE_SPAWN_OFFSET,99 size: PARTICLE_MIN_SIZE + Math.random() * PARTICLE_SIZE_RANGE * intensity,100 speed: PARTICLE_MIN_SPEED + Math.random() * PARTICLE_SPEED_RANGE,101// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from terrae
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Map Animated Circleanimated-circle | terrae | Components | Free | 1 dep | |
| Map Animated Footprintanimated-footprint | terrae | Components | Free | 2 deps | |
| Map Animated Polygonanimated-polygon | terrae | Components | Free | 1 dep | |
| Map Animated Pulseanimated-pulse | terrae | Components | Free | 1 dep | |
| Map Arc Animatedarc-animated | terrae | Components | Free | 1 dep | |
| Map Blur Areablur-area | terrae | Components | Free | 1 dep | |
| Map Camera Followcamera-follow | terrae | Components | Free | 1 dep | |
| Map Choroplethchoropleth | terrae | Components | Free | 1 dep |
