A small javascript library to generate a color palette.
npm install jpalette --save
Just download from here.
Use Webpack and/or Babel to bundle.
import * as jPalette from 'jpalette';
<script src="jpalette.min.js"></script>
There are two types of objects: Color and ColorMap.
A Color object is defined in RGBA format.
A ColorMap object is an array of Color.
You can retrieve a color with a normalized index between 0 and 1.
Here we generate a palette in 100 steps from red to green to blue.
let colorMap = new jPalette.ColorMap(100, [
new jPalette.Color(255, 0, 0, 255),
new jPalette.Color(0, 255, 0, 255),
new jPalette.Color(0, 0, 255, 255),
]);
// Normalized index between 0 and 1
let color = colorMap.getColor(0.3);
console.log(color);
// Color {r: 105, g: 149, b: 0, a: 255}
console.log(color.rgb());
// Return string for css use:
// rgb(0,206,48)
let colorMap = jPalette.ColorMap.get('sky')(1000);
Available palettes:
- whitetoblack
- blacknwhite
- rgb
- fire
- night
- sky
- rainbow
let color = jPalette.Color.get('cyan')(255); // Alpha transparancy set to 255
Available palettes:
- white
- black
- red
- green
- blue
- yellow
- cyan
- magenta
- indigo
- pink
- orange
- apple
- manganese
- guppie
- purple
- teal
- olive
- coral
npm run build