Skip to main content

Find the nearest W3C/X11 named colors to a given color

Project description

Nearest Colours

Find the nearest W3C/X11 named colors to a given color. This module, nearest_colour, provides two functions:

from typing import List, Literal, Union
from colour import Color

ColorSpace = Literal["hsv", "rgb", "yiq", "hls"]

def nearest_x11(color: Union[Color, str], n: int = 1, space: ColorSpace = "hls") -> List[Color]:
    pass


def nearest_w3c(color: Union[Color, str], n: int = 1, space: ColorSpace = "hls") -> List[Color]:
    pass

Each will return the n colors that are closest (Euclidean distance) to color in the specified color-space from either the set of W3C web colors or the set of Unix X11 colors. Web colors are standardized by W3C, whereas Unix X11 colors are defined in the X11 source-code. Note: these two sets of colors are almost entirely overlapping, but not completely. Colors may be provided as either colour Color objects, or as W3C colors strings. The default color-space for distance computation is HSL, which is perceptually uniform and therefore returns colors which are perceptually closer to the given color. A list is always returned, even if n == 1, and the ordering is from most similar to least similar. If you pass a large wnough integer (say, 256), you'll get the ranking for all colors in the respective set.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nearest-colour-1.0.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

nearest_colour-1.0.0-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page