Tiny Random Color Generator In JavaScript – randomColor.js

Category: Color , Javascript , Recommended | October 27, 2022
Author:davidmerfield
Views Total:150 views
Official Page:Go to website
Last Update:October 27, 2022
License:MIT

Preview:

Tiny Random Color Generator In JavaScript – randomColor.js

Description:

randomColor.js is a plain JavaScript library for generating random colors (rgb, rgba, rgbArray, hsl, hsla, hslArray, or hex) from a specific Hue and Saturation.

The random colors generated from randomColor.js are attractive and beautiful and can be used to colorize backgrounds, create buttons, or really anything that stands out. It takes the guesswork out of creating a nice color scheme for your next project.

How to use it:

1. Install & import the randomColor.js.

# NPM
$ npm i randomcolor
// CommonJS
var randomColor = require('randomcolor');
// CDN
<script src="https://cdn.jsdelivr.net/npm/[email protected]/randomColor.min.js"></script>

2. Generate a random color (hex).

randomColor();
// => #ff0000

3. Specify the number of colors to generate.

randomColor({
  count: 20
});

4. Set the hue of the colors: red, orange, yellow, green, blue, purple, pink, or monochrome.

randomColor({
  hue: 'red',
});

5. Set the luminosity of the colors: bright, light, or dark.

randomColor({
  luminosity: 'dark',
});

6. Set the color format: rgb, rgba, rgbArray, hsl, hsla, hslArray, or hex

randomColor({
  format: 'rgba',
});

7. Set the alpha channel, which specifies the opacity for an RGBA or HSLA color.

randomColor({
  alpha: 0.5,
});

8. Set the seed (seed) that will cause randomColor to return the same color each time.

randomColor({
  seed: 3,
});

You Might Be Interested In:


Leave a Reply