https://github.com/digiduncan/digicolor
Makes working with colors a bit nicer.
https://github.com/digiduncan/digicolor
Last synced: about 1 year ago
JSON representation
Makes working with colors a bit nicer.
- Host: GitHub
- URL: https://github.com/digiduncan/digicolor
- Owner: DigiDuncan
- License: gpl-3.0
- Created: 2020-03-27T20:58:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T19:50:49.000Z (almost 6 years ago)
- Last Synced: 2025-01-30T21:24:37.826Z (over 1 year ago)
- Language: Python
- Size: 54.7 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DigiColor
Makes working with colors a bit nicer.
**DigiColor** comes with a default pallete of 256 colors. If this is all you need, it's really simple to use out of the box:
```python
>>> from digicolor import colors
```
```python
>>> colors.RED
```
```python
Color(colorid = 1, name = "RED", value = 0x800000)
```
You can also "search" the global registry of colors by ID or name:
```python
>>> colors.fromID(2)
```
```python
Color(colorid = 2, name = "GREEN", value = 0x008000)
```
```python
>>> colors.fromName("BLUE")
```
```python
Color(colorid = 4, name = "BLUE", value = 0x000080)
```
You can look at the entire registry by accessing `colors.registry`...
```python
>>> print(colors.registry)
```
```python
[Color(colorid = 0, name = 'BLACK', value = 0x0), Color(colorid = 1, name = 'RED', value = 0x800000), Color(colorid = 2, name = 'GREEN', value = 0x8000), ...
```
...etc.
You can create your own colors by constructing one!
```python
>>> awesomecolor = colors.add(colorid = 256, name = "AWESOME", value = 0x0fcdf7)
>>> print(f"""Awesome Color
... ID: {awesomecolor.colorid}
... Name: {awesomecolor.name}
... Prettified Name: {awesomecolor.prettyName}
... Value: {awesomecolor.value}
... RGB: {awesomecolor.rgb}
... """)
```
```
Awesome Color
ID: 256
Name: AWESOME
Prettified Name: Awesome
Value: 1035767
RGB: (15, 205, 247)
```
And remove colors from the global registry:
```python
>>> awesomecolor.remove()
```
You can even get the closest approximation to a given color that your registry has:
```python
>>> colors.getClosestColor(0x00AA00)
```
```python
Color(colorid = 34, name = 'GREEN_3A', value = 0x00af00)
```
```python
>>> colors.getClosestColor("00AA00")
```
```python
Color(colorid = 34, name = 'GREEN_3A', value = 0x00af00)
```
```python
>>> colors.getClosestColor((0, 170, 0))
```
```python
Color(colorid = 34, name = 'GREEN_3A', value = 0x00af00)
```