Skip to content

Commit

Permalink
* added chroma.stdDeviation() to retrieve the variance in an array of…
Browse files Browse the repository at this point in the history
… colors as an RGBA component. See [Issue 328] (gka#328 (comment))

* added chroma.palette() to retrieve the n-most representative colors in an array of colors. See [Issue 328] (gka#328 (comment))

Signed-off-by: regorxxx <[email protected]>
  • Loading branch information
regorxxx committed Feb 20, 2024
1 parent 610ba7e commit cb8ac58
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,38 @@ And the available scales within a palette:
chroma.brewer.getPalette('Qualitative').slice(0, 2);
```

### chroma.palette
#### (colors, mode, n)

A helper function that computes a n-palette, based on input colors. It supports the modes [_contrast_ (c)](#chromacontrast), [_distance_ (d)](#chromadistance) and [_deltaE_ (de)](#chromadeltaE). Let's take a few colors as sample.

```js
var colors = ['#D2691E', '#8B4513', '#A0522D'
,'#0000FF', '#668B8B', '#FFC0CB'];
```

**[Contrast](#chromacontrast)** retrieves the n colors with highest contrast between them from the input colors:

```js
chroma.palette(colors, 'c', 2);
```

It also supports Chroma color objects as input, without needing to convert back an forth between formats:

```js
colors = colors.map(function (c) {return chroma(c)});
chroma.palette(colors, 'c', 2);
```

### chroma.stdDeviation
#### (colors)

A helper function that computes the standard deviation of input colors. Colors are internally parsed as [RGBA](#colorrgba) and output represents the mean RGBA component deviation. Divide it by 255 to get a percentage. Also supports Chroma color objects as input.

```js
chroma.stdDeviation(colors);
```

### chroma.limits
#### (data, mode, n)

Expand Down
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ chroma.analyze = require('./src/utils/analyze').analyze;
chroma.contrast = require('./src/utils/contrast');
chroma.deltaE = require('./src/utils/delta-e');
chroma.distance = require('./src/utils/distance');
chroma.stdDeviation = require('./src/utils/deviation');
chroma.palette = require('./src/utils/palette');
chroma.limits = require('./src/utils/analyze').limits;
chroma.valid = require('./src/utils/valid');
chroma.noHueAsZero = require('./src/utils/nohueaszero');
Expand Down

0 comments on commit cb8ac58

Please sign in to comment.