Skip to content

Commit

Permalink
docs(color): update readme (color sorting)
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 2, 2021
1 parent 75164aa commit ce79843
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/color/swatches-ex02.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions packages/color/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For the Clojure version, please visit: [thi.ng/color-clj](https://thi.ng/color-c
- [Color spaces / modes](#color-spaces--modes)
- [Class wrappers](#class-wrappers)
- [Color theme generation](#color-theme-generation)
- [Color sorting](#color-sorting)
- [RGBA transformations](#rgba-transformations)
- [RGBA Porter-Duff compositing](#rgba-porter-duff-compositing)
- [Cosine gradients](#cosine-gradients)
Expand Down Expand Up @@ -188,6 +189,24 @@ writeFileSync("export/swatches-ex01.svg", serialize(doc));

![example result color swatches](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/color/swatches-ex01.svg)

### Color sorting

The `sortColors()` function can be used to sort an array of colors using
arbitrary sort criteria. The following comparators are bundled:

- `selectChannel(i)` - sort by channel
- `proximityHSV(target)` - sort by distance to target color (HSV colors)
- `proximityRGB(target)` - sort by distance to target color (RGB colors)

```ts
// (see above example)
const colors = [...colorsFromTheme(theme, { num: 200, variance: 0.05 })];

sortColors(colors, proximityHSV([0,1,0.5]));
```

![sorted color swatches](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/color/swatches-ex02.svg)

### RGBA transformations

RGBA [color matrix
Expand Down
18 changes: 18 additions & 0 deletions packages/color/tpl.readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ writeFileSync("export/swatches-ex01.svg", serialize(doc));

![example result color swatches](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/color/swatches-ex01.svg)

### Color sorting

The `sortColors()` function can be used to sort an array of colors using
arbitrary sort criteria. The following comparators are bundled:

- `selectChannel(i)` - sort by channel
- `proximityHSV(target)` - sort by distance to target color (HSV colors)
- `proximityRGB(target)` - sort by distance to target color (RGB colors)

```ts
// (see above example)
const colors = [...colorsFromTheme(theme, { num: 200, variance: 0.05 })];

sortColors(colors, proximityHSV([0,1,0.5]));
```

![sorted color swatches](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/color/swatches-ex02.svg)

### RGBA transformations

RGBA [color matrix
Expand Down

0 comments on commit ce79843

Please sign in to comment.