ColorController is a Pythonic interface for managing colors by english-language name and various color values.

Overview

ColorController.py

Table of Contents

  1. Encode color data in various formats.
  2. Modify a color using simple, convenient methods.
  3. Invert a color
  4. Access a rich set of color values and color names

Welcome to the ColorController Python library!

My name is Tal Zaken, and I wrote this library for use in a natural language processing project that aims to take in free-form text, and spit out color data which somehow relates to the text's content.

Enough about that. Here are some things that you can do with ColorController:

1. Encode color data in various formats.

Example 1.1: Create a ColorController object using a familiar, english-language color name, and print out its properties.

You can set a color using a very large library of color names. See the colornames.txt document contained herein, with enormous thanks to Martin Krzywinski.

The following code:

from ColorController import ColorController

color = ColorController(name='hazel')

print(f"Name: {color.name}",
      f"Hex Code: {color.hex_code}",
      f"RGB: {color.rgb}",
      f"HSV: {color.hsv}",
      sep='\n')

outputs:

Name: hazel
Hex Code: ['#8E7618']
RGB: [(142, 118, 24)]
HSV: [(0.133, 0.831, 142)]

Further, you can change all the ColorController's properties by changing any one of them.

By example:

color.name = 'blue'

print(f"Name: {color.name}", 
      f"Hex Code: {color.hex_code}", 
      f"RGB: {color.rgb}", 
      f"HSV: {color.hsv}", 
      sep='\n')

You will see that all properties have updated:

Name: blue
Hex Code: ['#00008B', '#0000CD', '#0000EE', '#0000FF', '#0018A8', '#0087BD', '#0093AF', '#0247FE', '#0343DF', '#1F75FE', '#2242C7', '#333399']
RGB: [(0, 0, 139), (0, 0, 205), (0, 0, 238), (0, 0, 255), (0, 24, 168), (0, 135, 189), (0, 147, 175), (2, 71, 254), (3, 67, 223), (31, 117, 254), (34, 66, 199), (51, 51, 153)]
HSV: [(0.667, 1.0, 139), (0.667, 1.0, 205), (0.667, 1.0, 238), (0.667, 1.0, 255), (0.643, 1.0, 168), (0.548, 1.0, 189), (0.527, 1.0, 175), (0.621, 0.992, 254), (0.618, 0.987, 223), (0.602, 0.878, 254), (0.634, 0.829, 199), (0.667, 0.667, 153)]

Notably, the colornames.txt file has numerous entries that all share the name "blue." This is true of many colors. Because color is thought to be a culturally relative phenomenon, I have chosen to return all hex codes that match a given name. You will notice a similar phenomenon occurs for color names when you set a color using hex code, RGB, or HSV. This is because there are sometimes many names that all describe the same color.

Example 1.2: Show a color.

We've had a lot of talk about colors so far, but we haven't even seen any colors yet! Let's solve that now, and do away with these lengthy print statements:

color.hex_code ='#ffbff9'

color.show_color()

Shows:

pale_orchid

That said, the ColorController object is biased toward whatever you, the user, set it to be. If you explicitly set a name, then that will be the singular name of your object. Similarly, if you explicitly set a hex code, then that will be the value of your hex code. If you leave a leading # off of your hex code, then everything will still work, but that will be the hex code value. For example...

Example 1.3: Create a ColorController object using a hex code.

color = ColorController(hex_code='#990000')

color.show_color()

Shows:

['crimson_red', 'stizza', 'ou_crimson_red', 'usc_cardinal']

While:

color.hex_code = '990000'

color.show_color()

Shows very similar results:

['crimson_red', 'stizza', 'ou_crimson_red', 'usc_cardinal']

Example 1.4: Create a ColorController object using an RGB triplet.

You can also pass a 3-tuple whose values are each contained in range(0,256) to the rgb property. For example:

color = ColorController(rgb=(10, 255, 230))

color.show_color()

Shows:

[bright_aqua]

Example 1.5: Create a ColorController object using an HSV triplet, and print out its properties.

Lastly, you can also pass a 3-tuple whose first two values are a floating point number between 0 and 1 inclusive, and whose third value falls in range(0, 256):

color = ColorController(hsv=(0.25, 1, 255))

color.show_color()

Shows:

[chartreuse]

NOTE: While this is the HSV value format that comes included with the colorsys python standard library, it doesn't seem to be a very common format elsewhere. To match formats used in other locations, see the following functions:

def colorsys_hsv_to_hsv360(colorsys_hsv=tuple):
    """Takes an HSV triplet as provided by colorsys, and converts it to match the
    notation used in colornames.txt"""

def hsv360_to_hsvdistance(hsv360=tuple):
    """Takes an HSV triplet as provided by colorsys_hsv_to_hsv360(), and converts it to match the
    notation used in the function for calculating distance between colors."""  

2. Modify a color using simple, convenient methods.

Example 2.1: Darken a color.

You can darken a color using the darken_color() method. For example:

from ColorController import ColorController

color = ColorController(name='forest')

color.show_color()

color.darken_color()

color.show_color()

Will show the following in series:

[forest] [hunter_green]

You can also pass in a darkening_value between zero and one, to set the percent darker you'd like to go. For instance:

color = ColorController(name='cocoa')

color.show_color()

color.darken_color(.3)

color.show_color()

Shows the following in series:

[cocoa] [nutmeg]

In the above example, note that our color object was first initiated by the name property, meaning that there are lists of associated hex, rgb, and hsv values stored in their respective properties. When we lighten the color, we have to select one index from these lists to operate on. The default behavior is to operate on the first index. See the unlist() function in helpers.py.

Example 2.2: Lighten a color.

You can also pass in a lightening_value between zero and one, to set the percent lighter you'd like to go. For instance:

color = ColorController(hex_code='#6c3461')

color.show_color()

color.lighten_color(.5)

color.show_color()

Shows the following in series:

[grape] [grayish_fuchsia]

Example 2.3: Brighten a color.

3. Invert a color.

Example:

from ColorController.conversions import invert_rgb
from ColorController import ColorController


color = ColorController(hex_code='#9ffeb0')
color.show_color()

r, g, b = color.rgb
color.rgb = invert_rgb(r, g, b)
color.show_color()

Shows the following in series:

[mint] [deep_orchid]

4. Access a rich set of color values and color names (prepared by Martin Krzywinski), conveniently stored in a Pandas DataFrame.

Example:

from ColorController.ColorController import colors_df

print(colors_df.iloc[5000])

Outputs:

IDX                                                                  5000
NAME                                                    light_apple_green
rgb                                                                   rgb
R                                                                     220
G                                                                     231
B                                                                     139
hex                                                                   hex
HEX                                                               #DCE78B
hsv                                                                   hsv
h                                                                      67
s                                                                      40
v                                                                      91
xyz                                                                   xyz
X                                                                    0.63
Y                                                                    0.74
Z                                                                    0.35
lab                                                                   lab
L                                                                      89
A                                                                     -17
B                                                                      44
lch                                                                   lch
L                                                                      89
C                                                                      47
H                                                                     112
cmyk                                                                 cmyk
C                                                                       4
M                                                                       0
Y                                                                      36
K                                                                       9
NEIGHBOUR_STR           PMS586[775][226,229,132](3.6):hypnotic[4592][2...
NUM_NEIGHBOURS_MAXDE                                                    4
WORD_TAGS               [light, PMS586, hypnotic, jonquil, green, lime...
Name: 5000, dtype: object

Known Bugs:

  • I don't know of any right now, but I'm sure they exist!

Ideas

  • tint and shade methods instead of or in addition to lighten/darken?
  • more unit tests
  • module to mix colors
    • this will require converting to LAB or another subtractive space, so more getter/setter methods

Resources:

Owner
Tal Zaken
Tal Zaken
Produce a simulate-able SDF of an arbitrary mesh with convex decomposition.

Mesh-to-SDF converter Given a (potentially nasty, nonconvex) mesh, automatically creates an SDF file that describes that object. The visual geometry i

Greg Izatt 22 Nov 23, 2022
A python script to generate wallpaper

wallpaper eits Warning You need to set the path to Robot Mono font in the source code. (Settings are in the main function) Usage A script that given a

Henrique Tsuyoshi Yara 5 Dec 02, 2021
A sys-botbase client for remote control automation of Nintendo Switch consoles. Based on SysBot.NET, written in python.

SysBot.py A sys-botbase client for remote control automation of Nintendo Switch consoles. Based on SysBot.NET, written in python. Setup: Download the

7 Dec 16, 2022
A Python script that transcript Arcaea chart file (.aff file) into AutoJS touchscreen script which automatically plays the Arcaea chart

ArcaeaAutoplay (AutoJS Version) A Python script that transcript Arcaea chart file (.aff file) into AutoJS touchscreen script which automatically plays

7 Dec 03, 2021
Run functions in parallel easily, with their results typed correctly!

typesafe_parmap pip install pip install typesafe-parmap Run functions in parallel safely with typesafe parmap! GitHub: https://github.com/thejaminato

James Chua 3 Nov 06, 2021
Small project to interact with python, C, HTML, JavaScript, PHP.

Micro Hidroponic Small project to interact with python, C, HTML, JavaScript, PHP. Table of Contents General Info Technologies Used Screenshots Usage P

Filipe Martins 1 Nov 10, 2021
Personal Toolbox Package

Jammy (Jam) A personal toolbox by Qsh.zh. Usage setup For core package, run pip install jammy To access functions in bin git clone https://gitlab.com/

5 Sep 16, 2022
Course-parsing - Parsing Course Info for NIT Kurukshetra

Parsing Course Info for NIT Kurukshetra Overview This repository houses code for

Saksham Mittal 3 Feb 03, 2022
Aggregating gridded data (xarray) to polygons

A package to aggregate gridded data in xarray to polygons in geopandas using area-weighting from the relative area overlaps between pixels and polygons.

Kevin Schwarzwald 42 Nov 09, 2022
Airspy-Utils is a small software collection to help with firmware related operations on Airspy HF+ devices.

Airspy-Utils Airspy-Utils is a small software collection to help with firmware related operations on Airspy HF+ devices on Linux (and other free syste

Dhiru Kholia 11 Oct 04, 2022
Runes - Simple Cookies You Can Extend (similar to Macaroons)

Runes - Simple Cookies You Can Extend (similar to Macaroons) is a paper called "Macaroons: Cookies with Context

Rusty Russell 22 Dec 11, 2022
Writing Alfred copy/paste scripts in Python

Writing Alfred copy/paste scripts in Python This repository shows how to create Alfred scripts in Python. It assumes that you using pyenv for Python v

Will Fitzgerald 2 Oct 26, 2021
'ToolBurnt' A Set Of Tools In One Place =}

'ToolBurnt' A Set Of Tools In One Place =}

MasterBurnt 5 Sep 10, 2022
A morse code encoder and decoder utility.

morsedecode A morse code encoder and decoder utility. Installation Install it via pip: pip install morsedecode Alternatively, you can use pipx to run

Tushar Sadhwani 2 Dec 25, 2021
✨ Un générateur de mot de passe aléatoire totalement fait en Python par moi, et en français.

Password Generator ❗ Un générateur de mot de passe aléatoire totalement fait en Python par moi, et en français. 🔮 Grâce a une au module random et str

MrGabin 3 Jul 29, 2021
a demo show how to dump lldb info to ida.

用一个demo来聊聊动态trace 这个仓库能做什么? 帮助理解动态trace的思想。仓库内的demo,可操作,可实践。 动态trace核心思想: 动态记录一个函数内每一条指令的执行中产生的信息,并导入IDA,用来弥补IDA等静态分析工具的不足。 反编译看一下 先clone仓库,把hellolldb

25 Nov 28, 2022
Local backup made easy, with Python and shutil

KTBackup BETA Local backup made easy, with Python and shutil Features One-command backup and restore Minimalistic (only using stdlib) Convenient direc

kelptaken 1 Dec 27, 2021
Software to help automate collecting crowdsourced annotations using Mechanical Turk.

Video Crowdsourcing Software to help automate collecting crowdsourced annotations using Mechanical Turk. The goal of this project is to enable crowdso

Mike Peven 1 Oct 25, 2021
A simple, console based nHentai Code Generator

nHentai Code Generator A simple, console based nHentai Code Generator. How to run? Windows Android Windows Make sure you have python and git installed

5 Jun 02, 2022
Trying to replicate (albeit unsuccessfully) the phenomenon of boids using Ursina in a naive manner.

Boids_Boi Trying to replicate (albeit unsuccessfully) the phenomenon of boids using Ursina in a naive manner. Please install the Ursina module before

2 Oct 19, 2021