https://github.com/nottimtam/gradient.js
Create colorful gradient arrays in a single line of code.
https://github.com/nottimtam/gradient.js
Last synced: 3 months ago
JSON representation
Create colorful gradient arrays in a single line of code.
- Host: GitHub
- URL: https://github.com/nottimtam/gradient.js
- Owner: NotTimTam
- Created: 2022-01-25T22:57:24.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-03-01T04:11:49.000Z (about 4 years ago)
- Last Synced: 2025-01-30T05:47:38.957Z (about 1 year ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/gradient.js
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# gradient.js
Create colorful gradient arrays in a single line of code.
## Installation
Download the Github repo or run:
```
npm i gradient.js
```
## Usage
```js
const { Gradient } = require("gradient.js");
Gradient.create(
100,
"rgb(255, 209, 209)",
"#FBFFDE",
"#D7FDDF",
"#E0FFFD",
"hsl(240, 96%, 91%)",
"#F9DEFF"
);
```

(an image created using canvas and data from the above array)
### `Gradient.create(resolution, ...colors);`
`Gradient.create()` takes in a resolution, which determines how many colors to create in between each provided color. It is **always** the first argument. It is followed by the colors you want the gradient to move between. An unlimited number of colors, in any (CSS) accepted format can be used. An array of `rgba(r, g, b, a);` colors are returned.
### `Gradient.colorKeyMap`
`Gradient.colorKeyMap` is an array of every CSS color name and its corresponding RGBA value.
```js
black: [0, 0, 0, 1],
silver: [192, 192, 192, 1],
```
### `Gradient.convertToRGBA(color)`
`Gradient.convertToRGBA()` takes in any CSS accepted color and turns it into an RGBA array.
`[r, g, b, a]`
### `Gradient.rgbaStyler(rgba)`
`Gradient.rgbaStyler()` creates a formatted CSS-compatible string from an array.
i.e.: `[0, 0, 0, 0]` becomes `"rgba(0, 0, 0, 0)"`.