Skip to content

Commit

Permalink
improve readme and major bump
Browse files Browse the repository at this point in the history
  • Loading branch information
loucadufault committed Jan 7, 2022
1 parent f581a67 commit 1d2a5c0
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
A lightweight package to generate unique and uniformly sampled colors from UUIDs.
A lightweight package to deterministically generate unique and uniformly sampled colors from UUIDs.

The RGB color space is represented and spanned by hexadecimal numbers in the 0x000000 to 0xffffff range. We can use a simple modulo hash function (`% (0xffffff + 0x000001)` i.e. `% 0x100000`) to return numbers in that range from the decimal representation of the UUID (a base 10 39-digit integer). We then extract the red, green, and blue components from the resulting hash (which represents a specific color in hexadecimal notation) using bit masks.
### How it works

Since the color space is only 255^3 whereas the UUID space is much larger ([approximtely 5.3 x 10^36 possible UUIDs](https://www.uuidtools.com/what-is-uuid#overview)), it is impossible to create a complete bijection between the spaces, and so collisions in the generated color space are more likely to happen. This package does guarantee that the color space is maximally utilized, assuming a uniform distribution of the input UUIDs in the UUID space.
The RGB color space is represented by hexadecimal numbers in the 0x000000 to 0xffffff range. We use a simple modulo hash function (`% (0xffffff + 0x000001)` i.e. `% 0x100000`) to produce numbers in that range from the decimal representation of the UUID (a base 10 39-digit integer). We then extract the red, green, and blue components from the resulting hash (which represents a specific color in hexadecimal notation) using bit masks.

### Limitations

Since the color space is only 256^3 whereas the UUID space is much larger ([approximtely 5.3 x 10^36 possible UUIDs](https://www.uuidtools.com/what-is-uuid#overview)), it is impossible to create a complete bijection between the spaces, and so collisions in the generated color space can occur. This package does however guarantee that the color space is maximally utilized, assuming a uniform distribution of the input UUIDs within the UUID space.

# Installation:

Expand All @@ -22,7 +26,9 @@ const myUuid = uuidv4();
const hexColor = colorFromUuid(myUuid);
```

# Reference - v0.0.5
[Live demo](https://codesandbox.io/s/uuid-color-usage-o0e4o)

# Reference - v0.0.7

## Table of contents

Expand Down Expand Up @@ -60,4 +66,4 @@ The generated color as a CSS `<color>` notation string

#### Defined in

[index.ts:64](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L64)
[index.ts:64](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L64)
4 changes: 2 additions & 2 deletions docs/build/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Reference - v0.0.5
# Reference - v0.0.7

## Table of contents

Expand Down Expand Up @@ -36,4 +36,4 @@ The generated color as a CSS `<color>` notation string

#### Defined in

[index.ts:64](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L64)
[index.ts:64](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L64)
8 changes: 4 additions & 4 deletions docs/build/interfaces/Options.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Reference - v0.0.5](../README.md) / Options
[Reference - v0.0.7](../README.md) / Options

# Interface: Options

Expand All @@ -25,7 +25,7 @@ Colors are returned as strings in the CSS <color> data type hexadecimal or funct

#### Defined in

[index.ts:40](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L40)
[index.ts:40](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L40)

___

Expand All @@ -42,7 +42,7 @@ Only applies when the specified format is `"hsl"`, as this is the only output fo

#### Defined in

[index.ts:30](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L30)
[index.ts:30](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L30)

___

Expand All @@ -58,4 +58,4 @@ See [the Receivers type](../modules/internal_.md#receivers) for more details.

#### Defined in

[index.ts:49](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L49)
[index.ts:49](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L49)
6 changes: 3 additions & 3 deletions docs/build/modules/internal_.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Reference - v0.0.5](../README.md) / <internal\>
[Reference - v0.0.7](../README.md) / <internal\>

# Namespace: <internal\>

Expand All @@ -25,7 +25,7 @@

#### Defined in

[index.ts:15](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L15)
[index.ts:15](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L15)

___

Expand All @@ -35,4 +35,4 @@ ___

#### Defined in

[index.ts:13](https://github.com/loucadufault/uuid-color/blob/2177a9e/src/index.ts#L13)
[index.ts:13](https://github.com/loucadufault/uuid-color/blob/f581a67/src/index.ts#L13)
12 changes: 9 additions & 3 deletions docs/public/README.template.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
A lightweight package to generate unique and uniformly sampled colors from UUIDs.
A lightweight package to deterministically generate unique and uniformly sampled colors from UUIDs.

The RGB color space is represented and spanned by hexadecimal numbers in the 0x000000 to 0xffffff range. We can use a simple modulo hash function (`% (0xffffff + 0x000001)` i.e. `% 0x100000`) to return numbers in that range from the decimal representation of the UUID (a base 10 39-digit integer). We then extract the red, green, and blue components from the resulting hash (which represents a specific color in hexadecimal notation) using bit masks.
### How it works

Since the color space is only 255^3 whereas the UUID space is much larger ([approximtely 5.3 x 10^36 possible UUIDs](https://www.uuidtools.com/what-is-uuid#overview)), it is impossible to create a complete bijection between the spaces, and so collisions in the generated color space are more likely to happen. This package does guarantee that the color space is maximally utilized, assuming a uniform distribution of the input UUIDs in the UUID space.
The RGB color space is represented by hexadecimal numbers in the 0x000000 to 0xffffff range. We use a simple modulo hash function (`% (0xffffff + 0x000001)` i.e. `% 0x100000`) to produce numbers in that range from the decimal representation of the UUID (a base 10 39-digit integer). We then extract the red, green, and blue components from the resulting hash (which represents a specific color in hexadecimal notation) using bit masks.

### Limitations

Since the color space is only 256^3 whereas the UUID space is much larger ([approximtely 5.3 x 10^36 possible UUIDs](https://www.uuidtools.com/what-is-uuid#overview)), it is impossible to create a complete bijection between the spaces, and so collisions in the generated color space can occur. This package does however guarantee that the color space is maximally utilized, assuming a uniform distribution of the input UUIDs within the UUID space.

# Installation:

Expand All @@ -22,4 +26,6 @@ const myUuid = uuidv4();
const hexColor = colorFromUuid(myUuid);
```

[Live demo](https://codesandbox.io/s/uuid-color-usage-o0e4o)

{{/docs/build/README.md}}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uuid-color",
"version": "0.0.7",
"version": "0.1.0",
"description": "A lightweight package to generate unique and uniformly sampled colors from UUIDs.",
"main": "lib/index.js",
"scripts": {
Expand Down

0 comments on commit 1d2a5c0

Please sign in to comment.