1.0.5 • Published 5 months ago

mesh-gradient-ts v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

Mesh gradient 🎨

A lightweight and customizable mesh gradient animation (or static image) generator for web applications.

With configurable colors, movements and effects.

Description

This package provides a simple way to create animated mesh gradients using HTML5 Canvas. It generates smooth, organic-looking gradients that can animate and morph between colors. Perfect for modern web designs, hero backgrounds, or any UI element requiring dynamic visual background.

Preview

Preview

Installation

npm install mesh-gradient-ts

Usage

import { MeshGradient } from 'mesh-gradient-ts';

const gradient = new MeshGradient(canvas, { 
  backgroundColor: '#222222',
  colors: ['#1034a6', '#7851a9', '#191970'], 
  density: 10, 
  radius: 1000, 
  blurAmount: 100,
  noiseIntensity: 10,
  speed: 10, 
  morphSpeed: 0.02,
  isStatic: false
});

Configuration Options

The MeshGradient constructor accepts the following options:

ParameterTypeDefaultDescription
backgroundColorstring'#222222'Background color in hex format
colorsstring[]'#1034a6', '#7851a9', '#191970'Array of colors in hex format that will be used for the gradient points
densitynumber5Number of gradient points to generate (max 20)
radiusnumber1000Radius of each gradient point
blurAmountnumber100Blur intensity of the gradients
noiseIntensitynumber10Intensity of the noise effect (0-255)
speednumber10Movement speed of the gradient points
morphSpeednumber0.02Speed at which colors morph between each other (0-1)
isStaticbooleanfalseIf true, generates a static gradient instead of an animation

Methods

Control Methods

MethodParametersDescription
pause()NonePauses the animation
resume()NoneResumes the animation
setBackgroundColor()color: stringUpdates the background color (hex format)
setColors()colors: string[]Updates the gradient colors
setDensity()density: numberUpdates the number of gradient points
setRadius()radius: numberUpdates the radius of gradient points
setBlurAmount()blurAmount: numberUpdates the blur effect amount
setSpeed()speed: numberUpdates the movement speed of gradient points
setNoiseIntensity()noiseIntensity: numberUpdates the noise intensity (0-255)
setMorphSpeed()speed: numberUpdates the morphing speed (0-1)
exportImage()format?: 'png' \| 'jpeg' quality?: number width?: number height?: numberExports the current gradient as an image

Dependencies

This package uses:

  • Canvas API
  • OffscreenCanvas
  • RequestAnimationFrame

Build

npm run build
npx tsc --declaration --emitDeclarationOnly --outDir dist

License

MIT

About

Made by Romain Nugou.

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago