Skip to content

Commit b1f9a0e

Browse files
authored
Update README.md
1 parent c951dfe commit b1f9a0e

1 file changed

Lines changed: 37 additions & 30 deletions

File tree

README.md

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
Have you ever thought to yourself, "man, I really wish I could make this plot a random color so debugging is less boring"?
44

5-
Or maybe: "I need 20 different colors for my chart but I don't want them to look too similar"
5+
Alternatively, "I need 20 different colors for my chart, but I don't want them to look too similar."
66

7-
Well congratulations, you've just found the package for that. Just simply do:
7+
Congratulations! You've just located the right package/library! Just do:
88

99
```python
1010
import random_color_hex as RCH
@@ -47,7 +47,7 @@ Each line gets its own random color
4747

4848
## The Cool Part: Smart Color Separation
4949

50-
Here's where it gets interesting - this library can make sure your colors are actually different from each other:
50+
This library is special in that it uses Gaurav Sharma's 2001 paper CIEDE2000 to calculate the distance between colors actually ***looks*** different versus just being a random color. (See below for continued discussion on this topic)
5151

5252
```python
5353
import random_color_hex as RCH
@@ -59,15 +59,21 @@ color3=RCH.main(HowDifferentShouldColorsBe='L') # Different from both
5959
```
6060

6161
The `HowDifferentShouldColorsBe` parameter controls the minimum distance between colors:
62-
- `'s'` (small) - Slightly different (default)
63-
- `'m'` (medium) - Clearly different
62+
- `'s'` (small) - Slightly different
63+
- `'m'` (medium) - Clearly different (default)
6464
- `'l'` (large) - Very different
6565
- `'sl'` (super large) - Extremely different
6666

6767
This is perfect when you need multiple colors that won't blend together
6868

6969
---
7070

71+
For most people, this will be enough no problems. However, for individuals who are using dozens of colors in one run of a program, trying to get colors that are distinct becomes less relevant than getting colors out. This also has a backup to allow for standard RGB generation. This ensures that the program never gets stuck trying to generate a "unique" color forever if you really just want 50000 colors.
72+
73+
If the program gets stuck, it will let you know and request you lower your separation. If you don't, it will assume you want just a high amount of colors and will generate them with no separation. No human interaction is required for this!
74+
75+
Each color is generated using the secrets module as well, meaning the colors are near true random.
76+
7177
## Install
7278

7379
```bash
@@ -124,7 +130,7 @@ color=RCH.main(SuperLightColorsAllowed=False, SuperDarkColorsAllowed=False)
124130

125131
---
126132

127-
## Advanced Usage
133+
## Other Useful Functions
128134

129135
### Instance-Based Generation (Stateful)
130136

@@ -153,7 +159,7 @@ color=RCH.BasicMain() # Fast, simple, no distance checking
153159

154160
## Real-World Examples
155161

156-
### Example 1: Multi-Line Plot with Distinct Colors
162+
### Example 1: Multi-Line Plot with Super Distinct Colors
157163

158164
```python
159165
import matplotlib.pyplot as plt
@@ -164,13 +170,13 @@ import numpy as np
164170
x=np.linspace(0, 10, 100)
165171

166172
# Plot with guaranteed distinct colors using direct call
167-
plt.plot(x, np.sin(x), color=RCH.main(HowDifferentShouldColorsBe='L'), label='sin(x)')
168-
plt.plot(x, np.cos(x), color=RCH.main(HowDifferentShouldColorsBe='L'), label='cos(x)')
169-
plt.plot(x, np.sin(2*x), color=RCH.main(HowDifferentShouldColorsBe='L'), label='sin(2x)')
170-
plt.plot(x, np.cos(2*x), color=RCH.main(HowDifferentShouldColorsBe='L'), label='cos(2x)')
173+
plt.plot(x, np.sin(x), color=RCH.main(HowDifferentShouldColorsBe='SL'), label='sin(x)')
174+
plt.plot(x, np.cos(x), color=RCH.main(HowDifferentShouldColorsBe='SL'), label='cos(x)')
175+
plt.plot(x, np.sin(2*x), color=RCH.main(HowDifferentShouldColorsBe='SL'), label='sin(2x)')
176+
plt.plot(x, np.cos(2*x), color=RCH.main(HowDifferentShouldColorsBe='SL'), label='cos(2x)')
171177

172178
plt.legend()
173-
plt.title("Trig Functions with Distinct Colors")
179+
plt.title("Trig Functions with Super Distinct Colors")
174180
plt.show()
175181
```
176182

@@ -180,15 +186,17 @@ plt.show()
180186
import matplotlib.pyplot as plt
181187
import random_color_hex as RCH
182188

183-
categories=['Python', 'JavaScript', 'Java', 'C++', 'Ruby']
184-
values=[85, 70, 65, 50, 45]
189+
categories=['Python', 'JavaScript', 'Java', 'C++', 'Kotlin']
190+
values=[100, -20, 65, 90, 45]
185191

186192
# Direct usage in bar chart - each bar gets a unique color
187193
for i, (cat, val) in enumerate(zip(categories, values)):
188194
plt.bar(cat, val, color=RCH.main(SuperLightColorsAllowed=False))
189195

190196
plt.title("Programming Language Popularity")
191197
plt.ylabel("Score")
198+
plt.xlabel("Language")
199+
plt.xticks(rotation=39)
192200
plt.show()
193201
```
194202

@@ -251,20 +259,18 @@ Excludes:
251259
- Near-white colors (like #FFFFFF, #FEFEFE)
252260
- Light pastels (like light pink #FFB0B0, light blue #B0B0FF)
253261
- Light grays and neutral tones
254-
- Any color where all RGB channels are high
255262

256263
### SuperDarkColorsAllowed=False
257264
Excludes:
258265
- Near-black colors (like #000000, #0A0A0A)
259266
- Very dark shades
260-
- Colors where all RGB channels are very low
261267

262268
### HowDifferentShouldColorsBe
263-
Uses Euclidean distance in RGB space to ensure colors are separated:
264-
- `'s'`: ~10 units apart (subtle difference, can generate ~8400 colors)
265-
- `'m'`: ~25 units apart (clear difference, can generate ~770 colors)
266-
- `'l'`: ~40 units apart (strong difference, can generate ~220 colors)
267-
- `'sl'`: ~80 units apart (maximum contrast, can generate ~36 colors)
269+
Uses CIEDE2000 (ΔE00) perceptual distance to ensure colors are separated:
270+
- `'s'`: ~10 units apart (subtle difference, can generate ~663 colors)
271+
- `'m'`: ~25 units apart (clear difference, can generate ~68 colors)
272+
- `'l'`: ~30 units apart (strong difference, can generate ~40 colors)
273+
- `'sl'`: ~40 units apart (maximum contrast, can generate ~23 colors)
268274

269275
**Note:** The algorithm will keep searching for valid colors, but generation slows down as you approach these limits
270276

@@ -273,14 +279,15 @@ Uses Euclidean distance in RGB space to ensure colors are separated:
273279
## Technical Notes
274280

275281
* **Zero deps:** stdlib-only; uses `secrets` for cryptographically random colors
276-
* **OS:** Works on Windows/macOS/Linux - if it can run Python 3.11, this can run
277-
* **Python:** >=3.11.0 (uses match/case statements)
282+
* **OS:** Works on Windows/macOS/Linux/Raspberry Pi/z OS - if it can run Python 3.11, this can run.
283+
* **Python:** >=3.11.0
278284
* **Algorithm:** Smart RGB distance checking to ensure color separation
279285
* **Performance:** Fast for reasonable numbers of colors. Maximum practical limits:
280-
- Small distance ('s'): ~8400 colors
281-
- Medium distance ('m'): ~770 colors
282-
- Large distance ('l'): ~220 colors
283-
- Super large distance ('sl'): ~36 colors
286+
- Small distance ('s'): ~663 colors
287+
- Medium distance ('m'): ~68 colors
288+
- Large distance ('l'): ~40 colors
289+
- Super large distance ('sl'): ~23 colors
290+
- After the program runs, and you plot your colors, the colors saved are reset.
284291
* **Thread-safe:** Uses `secrets` module for random generation
285292
* **License:** Unlicense (public domain) - Do whatever you want
286293

@@ -307,22 +314,22 @@ Uses Euclidean distance in RGB space to ensure colors are separated:
307314
### Parameters
308315
- `SuperLightColorsAllowed` (bool): Allow near-white/pastel colors (default: True)
309316
- `SuperDarkColorsAllowed` (bool): Allow near-black colors (default: True)
310-
- `HowDifferentShouldColorsBe` (str): Color separation ['s', 'm', 'l', 'sl'] (default: 's')
317+
- `HowDifferentShouldColorsBe` (str): Color separation ['s', 'm', 'l', 'sl'] (default: 'm')
311318

312319
---
313320

314321
## Fun Facts
315322

316-
- The library uses cryptographic randomness (`secrets` module) - your colors are unpredictable
317323
- The color separation algorithm runs in real-time, continuously generating until it finds a suitable color
318-
- With maximum separation ('sl'), you're essentially creating a maximally diverse color palette
324+
- With any setting at its max, you're essentially creating a maximally diverse color palette
319325
---
320326

321327
## Links
322328

323329
* **PyPI:** [https://pypi.org/project/random-color-hex/](https://pypi.org/project/random-color-hex/)
324330
* **Source:** [https://github.com/BobSanders64/RandomColorHex](https://github.com/BobSanders64/RandomColorHex)
325331
* **Author:** Nathan Honn (randomhexman@gmail.com)
332+
326333
---
327334

328335
Enjoy your daily dose of randomness

0 commit comments

Comments
 (0)