Map Sandstorm
terrae/sandstormFreeComponent
Atmospheric sandstorm effect with horizontal particle movement and reduced visibility.
Install it
npx shadcn@latest add https://www.terrae.dev/sandstorm.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 SandParticle = {14 x: number15 y: number16 size: number17 speed: number18 opacity: number19 wobble: number20 wobbleSpeed: number21}2223type SandstormControl = {24 start: () => void25 stop: () => void26 setIntensity: (intensity: number) => void27 isActive: boolean28}2930type SandstormOverlayProps = {31 intensity: number32 particleCount: number33 color: string34 windSpeed: number35 windDirection: number36 visibility: number37 turbulence: number38 isActive: boolean39 onControlReady: (control: SandstormControl) => void40}4142type MapSandstormProps = {43 id?: string44 intensity?: number45 particleCount?: number46 color?: string47 windSpeed?: number48 windDirection?: number49 visibility?: number50 turbulence?: number51 autoStart?: boolean52}5354const DEFAULT_INTENSITY = 155const DEFAULT_PARTICLE_COUNT = 20056const DEFAULT_COLOR = "#d4a574"57const DEFAULT_WIND_SPEED = 458const DEFAULT_WIND_DIRECTION = 059const DEFAULT_VISIBILITY = 0.360const DEFAULT_TURBULENCE = 0.56162const MIN_INTENSITY = 0.163const MAX_INTENSITY = 364const BOUNDS_PADDING = 1065const PARTICLE_MIN_SIZE = 166const PARTICLE_SIZE_RANGE = 367const PARTICLE_MIN_SPEED = 268const PARTICLE_SPEED_RANGE = 469const PARTICLE_MIN_OPACITY = 0.370const PARTICLE_OPACITY_RANGE = 0.571const PARTICLE_MIN_WOBBLE_SPEED = 0.0272const PARTICLE_WOBBLE_SPEED_RANGE = 0.0473const DEGREES_TO_RADIANS = Math.PI / 18074const TURBULENCE_MULTIPLIER = 2075const VERTICAL_WOBBLE_FACTOR = 0.176const HAZE_OPACITY_FACTOR = 0.477const CONTROL_UPDATE_INTERVAL = 10078const DEFAULT_SAND_RGB: RgbColor = { red: 212, green: 165, blue: 116 }7980const sandstormControls = new Map<string, SandstormControl>()8182const hexToRgb = (hex: string): RgbColor => {83 const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex)8485 if (!result) {86 return DEFAULT_SAND_RGB87 }8889 return {90 red: parseInt(result[1], 16),91 green: parseInt(result[2], 16),92 blue: parseInt(result[3], 16),93 }94}9596const createParticle = (97 canvasWidth: number,98 canvasHeight: number,99 windDirection: number,100 intensity: number101): SandParticle => {102 const angle = windDirection * DEGREES_TO_RADIANS103 const startFromLeft = Math.cos(angle) > 0104105 return {106 x: startFromLeft ? -BOUNDS_PADDING : canvasWidth + BOUNDS_PADDING,107 y: Math.random() * canvasHeight,108// … 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 |
