Skip to main content

A flexible color library

Project description

Painto

A flexible color library for Python with support for multiple color formats, arithmetic operations, and extensive color collections.

Quick Start

import painto

# Create colors from names, hex, or RGB values
red = painto.red
blue = painto.Color("#0000ff")
green = painto.Color(0, 255, 0)

# Basic color properties
print(red.hex)        # "#ff0000"
print(red.rgb)        # (255, 0, 0)
print(red.hsv)        # (0.0, 1.0, 1.0)

# Color arithmetic
purple = red + blue
darker_red = red / 2
lighter_blue = blue * 2

# Generate color ranges
gradient = list(panto.color_range(red, blue, 5))

Key Features

  • Multiple Input Formats: Names, hex strings, RGB/RGBA tuples
  • Color Collections: W3C, XKCD
  • Color Spaces: RGB, HSV, HSL, and grayscale conversion
  • Console Output: ANSI color codes for terminal display

Basic Usage

Creating Colors

All color names from w3c/css, the XKCD color list, pride are available and searched in that order, so red (in all three lists) will return the w3c red unless another list is specifically requested.

# From color names
red = painto.red
blue = painto.blue

# From specific color spaces:

red = painto.xkcd.red  # XKCD red is #e50000

# From hex strings
purple = painto.Color("#800080")
transparent_red = painto.Color("#ff000080")  # With alpha

# From RGB values
green = painto.Color(0, 255, 0)
yellow = painto.Color(255, 255, 0, 128)  # With alpha

# Random
new_color = painto.random_color()
new_w3c_color = painto.w3c.random()
new_colors = painto.xkcd.random(10)  # will return a list of colors from the list

# For contrasting text, this returns black or white, depending on which is
# more contrasting, for use as text on a <color> background, for instance.
foreground = yellow.foreground  # Will return black, for yellow

Color Properties

color = painto.orange

print(color.r, color.g, color.b, color.a)  # 255 165 0 255
print(color.hex)                            # "#ffa500"
print(color.name)                           # "orange"
print(color.luminosity)                     # 0.696
print(color.hsv)                            # (0.108, 1.0, 255)

Color Operations

red = painto.red
blue = painto.blue

# Blend colors
purple = red + blue

# Scale brightness
darker = red / 2
lighter = blue * 2

Color Ranges

# Generate gradient between colors
colors = painto.color_range(Color("red"), Color("blue"), 10)  # 10 steps

# Inclusive range (includes end color)
colors = painto.color_range(Color("red"), Color("blue"), 5, inclusive=True)

Console Output

color = painto.green
print(f"Here is some {color.console_string("Green text")}")
print(f"And some {color.console_string_bg("Green background with contrasting text")}")

Installation

pip install painto

Documentation

For more information, see the complete documentation

License

MIT License - see LICENSE file for details.

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

painto-0.3.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

painto-0.3.0-py3-none-any.whl (23.2 kB view details)

Uploaded Python 3

File details

Details for the file painto-0.3.0.tar.gz.

File metadata

  • Download URL: painto-0.3.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.6 Windows/11

File hashes

Hashes for painto-0.3.0.tar.gz
Algorithm Hash digest
SHA256 289dbfa003852e3c2dbb107ae511dfdbd1e1e8905630377d4d31b7f87ec0cac4
MD5 4ba40d2bc13e4f7f5c128f55f0e6ad4b
BLAKE2b-256 659cbee459ccbce589539e53a5bff431c9082149bd7eedc92473611ee6460f30

See more details on using hashes here.

File details

Details for the file painto-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: painto-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 23.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.12.6 Windows/11

File hashes

Hashes for painto-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f47e65d0207471d923d751103c1328fe22f984da1362478ad7b5c7f527472863
MD5 04c71f6734d344e7010ea9d227fcddde
BLAKE2b-256 91965d1e0e7f76a3bf1c5872e5628f79b68ac190e27c898a9b16cdc5e4f30fe9

See more details on using hashes here.

Supported by

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