A tiny utility library to generate mesh gradient based on 4 RGB colors, built with vanilla js.

Overview

MeshGradient.js

mesh-gradient.js is tiny utility library to generate mesh gradient based on 4 RGB colors, built with vanilla js.

mesh-610

Installation!

npm install mesh-gradient.js or yarn add mesh-gradient.js

Basic Usage

Vanilla JS


React

import MeshGradient from 'mesh-gradient.js';
import { useEffect } from 'react';

const COLORS =   ["#eb75b6",
"#ddf3ff",
"#6e3deb",
"#c92f3c"]

function App() {

// create instance of Gradient Class
  const gradient = new MeshGradient();
  const canvasId = "my-canvas"

  useEffect(() => {
    // initialize new gradient
    // @Params
    // 1. id of canvas elememt
    // 2. array of colors in hexcode
    gradient.initGradient("#" + canvasId, COLORS) 
    // Mesh Id 
    // Any positive numeric value which acts as a seed for mesh pattern
    gradient?.changePosition(780); 
  }, [])

  const regenerate = () => {
    const value = Math.floor(Math.random() * 1000)
    // change pattern by changing mesh Id
    gradient?.changePosition(value);
  }

  return (
    <div className="App">
        <canvas id={canvasId} width="800" height="600"/>
        <button onClick={() => regenerate()}> Regenerate </button>
    </div>
  );
}

export default App;

Other Useful APIs

// get current gradient colors
gradient.getGradientColors(),

// change gradient colors
gradient.changeGradientColors(newColors);

// force refresh mesh
// Usage - set any property of the Mesh Gradient Object and run this to see the effect
gradient.reGenerateCanvas();

Mesh Gradient Model

{
    isLoadedClass: boolean;
    el: any;
    inputColors: any;
    connect(): Promise<void>;
    shaderFiles: {
        vertex: string;
        noise: string;
        blend: string;
        fragment: string;
    } | undefined;
    conf: {
        presetName: string;
        wireframe: boolean;
        density: number[];
        zoom: number;
        rotation: number;
        playing: boolean;
    } | undefined;
    minigl: MiniGl | undefined;
    disconnect(): void;
    setCanvasSize(width: any, height: any, initial?: boolean): void;
    width: any;
    height: any;
    xSegCount: number | undefined;
    ySegCount: number | undefined;
    initMaterial(): any;
    uniforms: {
        u_time: any;
        u_shadow_power: any;
        u_darken_top: any;
        u_active_colors: any;
        u_global: any;
        u_vertDeform: any;
        u_baseColor: any;
        u_waveLayers: any;
    } | undefined;
    vertexShader: string | undefined;
    initMesh(): void;
    material: any;
    geometry: any;
    mesh: any;
    shouldSkipFrame(e: any): true | undefined;
    updateFrequency(e: any): void;
    toggleColor(index: any): void;
    showGradientLegend(): void;
    isGradientLegendVisible: boolean | undefined;
    hideGradientLegend(): void;
    changePosition(val: any): void;
    t: number | undefined;
    init(): void;
    initGradientColors(): void;
    sectionColors: any;
    changeGradientColors(colors: any): void;
    reGenerateCanvas(): void;
    getGradientColors(): any;
}

Credits

  • Stripe - https://stripe.com
  • kevinhufnagl - https://kevinhufnagl.com/
You might also like...

A tiny, plugin extendable JavaScript utility library with a JQuery-like syntax.

A tiny, plugin extendable JavaScript utility library with a JQuery-like syntax.

Tiny Friggin' Utility Zapper What is it? A tiny ~7kb extendable JavaScript utility library with a JQuery like syntax for getting work done fast! If yo

Jun 25, 2022

A utility for creating toggleable items with JavaScript. Inspired by bootstrap's toggle utility. Implemented in vanillaJS in a functional style.

LUX TOGGLE Demo: https://jesschampion.github.io/lux-toggle/ A utility for creating toggleable dom elements with JavaScript. Inspired by bootstrap's to

Oct 3, 2020

Tiny and fast utility to extract all possible values for a given enum.

Tiny (208B) and fast utility to extract all possible values for a given enum.

Apr 18, 2022

A vanilla javascript library to generate Avataaars on the client or server side!

A vanilla javascript library to generate Avataaars on the client or server side!

Use the awesome Avataaars Library by Pablo Stanley (avataaars.com) in any javascript application. This Project uses parts of the Dicebear Avatars Libr

Dec 4, 2022

A small javascript DOM manipulation library based on Jquery's syntax. Acts as a small utility library with the most common functions.

Quantdom JS Quantdom is a very small (about 600 bytes when ran through terser & gzipped) dom danipulation library that uuses a Jquery like syntax and

Aug 16, 2022

Vanilla JavaScript tabs - tiny and simple.

Vanilla JavaScript Tabs Vanilla JavaScript Tabs - simple and awesome. — Inspired by the blazing fast, lightweight, cross-platform and crazy popular Va

Dec 22, 2022

Utility to generate adwaita presets for use with AdwCustomizer from images using Google's MaterialU color generator.

Utility to generate adwaita presets for use with AdwCustomizer from images using Google's MaterialU color generator.

Adwaita Preset Generator using Material U Color Generation Material U Color generation is done using the material-color-utilities available here: http

Oct 31, 2022

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js

This is a vanilla Node.js rest API created to show that it is possible to create a rest API using only vanilla Node.js. But in most cases, I would recommend you to use something like Express in a production project for productivity purposes.

Jul 19, 2022

Personalize your GitHub experience by theming the site's accent colors.

Personalize your GitHub experience by theming the site's accent colors.

· Gitccentify · Personalize your GitHub experience by theming it to your own style! Disclaimer This project is not affiliated, associated, authorized,

Nov 30, 2022
Owner
Anup Aglawe
Building uxie.io . Developing tools to improve developer productivity.
Anup Aglawe
🎨 Generate CSS Mesh Gradients

?? Meshgrad Meshgrad is a tiny utility to generate native-CSS Mesh Gradients. Demo - meshgrad.cretu.dev Install $ npm install meshgrad Use Vanilla Jav

Cristian Crețu 17 Dec 31, 2022
chakra-radix-colors provides radix-ui color palettes, automatic dark mode, and acessible colors to chakra-ui applications

chakra-radix-colors chakra-radix-colors provides radix-ui color palettes, automatic dark mode, and acessible colors to chakra-ui applications. About C

null 11 Dec 30, 2022
Web based all in one gradient editor for your next projects.

Find the perfect gradient for your next projects Introducing Gradientify Gradientify is a web-based all-in-one gradient editor that gives you access t

Nitin Singh 21 Dec 25, 2022
Web-based tool to build gradient data for retro platforms using a visual editor

Gradient Blaster https://gradient-blaster.grahambates.com Gradient Blaster is a web-based tool to build gradient data for retro platforms using a visu

Graham Bates 5 Dec 13, 2022
Colr Pickr, a vanilla JavaScript color picker component built with SVGs, with features like saving colors. Similar design to the chrome-dev-tools color picker.

Colr Pickr Colr Pickr, a vanilla JavaScript color picking component built with SVGs, with features like saving colors. Similar design to the chrome-de

TEK 27 Jun 27, 2022
Library for controlling MESH blocks using JavaScript.

MESH.js Library for controlling MESH blocks using JavaScript. MESH official web site is here. Verified Environment Node.js (16.15.1) npm (8.11.0) Prer

MESH project 6 Nov 22, 2022
🤍 Custom gradient image generator

Gradient Gradient is a custom gradiant making web app. Use it here Features Custom Gradient Making Using Sliders And Color Picker Use Ready Made Gradi

Dopevog 15 Sep 10, 2021
A flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh

three-bvh-csg An experimental, in progress, flexible, memory compact, fast and dynamic CSG implementation on top of three-mesh-bvh. More than 100 time

Garrett Johnson 208 Jan 5, 2023
A mesh network that connects remote communities to emergency responders without relying on internet, cell towers, or satellites

A mesh network that connects remote communities to emergency responders without relying on internet, cell towers, or satellites. Winner of Hack the North 2022. ??

Alice Cai 4 Sep 23, 2022
A NodeJS package to convert any RGB color to HEX color or viceversa. Also supports HSL conversion.

Unhex ?? A NodeJS package to convert any RGB color to HEX, HSL color or viceversa. Example div { color: #fff; background-color: #0070f3; } After r

Arnau Espin 2 Oct 1, 2022