Skip to main content

Advanced color manipulation library for gradients and conversions

Project description

Chromatica - Advanced Color Manipulation Library

Chromatica is a powerful Python library for advanced color manipulation, gradient generation, and color space conversions. Designed for graphics programming, data visualization, and image processing, Chromatica provides intuitive tools for working with colors in various formats and creating stunning gradients with mathematical precision.

Key Features

  • Multi-format Color Support: Work with RGB, HSV, HSL, CMYK, RGBA, and more
  • Advanced Gradient Generation: Create linear, radial, and angular gradients
  • Color Space Conversions: Convert between color spaces with precision
  • Vectorized Operations: Optimized numpy-based operations for performance
  • PIL/Pillow Integration: Seamlessly work with images
  • Mathematical Precision: Unit-tested color transformations

Installation

pip install chromatica

Quick Start

Color Conversion

from chromatica import convert, ColorRGB, ColorHSV

# Simple color conversion
rgb = (255, 0, 0)  # Red
hsv = convert(rgb, from_space='rgb', to_space='hsv')
print(f"Red in HSV: {hsv}")  # (0, 100, 100)

# Using color classes
red_rgb = ColorRGB((255, 0, 0))
red_hsv = red_rgb.to_hsv()
print(f"Red as HSV object: {red_hsv}")  # ColorHSV((0, 100, 100))

Gradient Generation

from chromatica import Gradient1D, Gradient2D

# Create a 1D gradient from red to blue
gradient_1d = Gradient1D.from_colors(
    color1=(255, 0, 0),
    color2=(0, 0, 255),
    steps=100
)

# Create a 2D gradient from four corner colors
gradient_2d = Gradient2D.from_colors(
    color_tl=(255, 0, 255),   # Top-left: pink
    color_tr=(255, 255, 0),   # Top-right: yellow
    color_bl=(255, 0, 128),   # Bottom-left: deep pink
    color_br=(255, 128, 0),   # Bottom-right: orange
    width=500,
    height=500
)

# Save as image
from PIL import Image
Image.fromarray(gradient_2d.colors.astype(np.uint8), mode='RGB').save('gradient.png')

Radial Gradient

from chromatica import radial_gradient
import numpy as np

# Create radial gradient
gradient = radial_gradient(
    color1=(0, 0, 255, 0),    # Blue with full transparency
    color2=(0, 0, 0, 255),    # Black with full opacity
    height=500,
    width=500,
    center=(250, 250),
    radius=125,
    color_mode='RGBA'
)

# Display
Image.fromarray(gradient.astype(np.uint8), mode='RGBA').show()

Documentation

Core Components

  1. Color Classes:

    • ColorRGB, ColorHSV, ColorHSL, ColorRGBA, etc.
    • Convert between color spaces
    • Normalize values and clamp ranges
  2. Gradient Generators:

    • Gradient1D: Linear color gradients
    • Gradient2D: 2D color fields from corner colors
    • radial_gradient: Radial color transitions
  3. Color Space Conversions:

    • Convert between RGB, HSV, HSL
    • Support for integer, float, and PIL-specific formats
    • Vectorized numpy operations

Advanced Usage

# Create gradient with custom easing function
import numpy as np

gradient = Gradient1D.from_colors(
    color1=(255, 0, 0),
    color2=(0, 0, 255),
    steps=100,
    unit_transform=lambda x: (1 - np.cos(x * np.pi)) / 2  # Smooth easing
)

# Angular gradient wrapping
rotated = gradient.wrap_around(
    width=500,
    height=500,
    center=(250, 250),
    angle_start=0,
    angle_end=2 * np.pi
)

Examples

Check out the examples in the examples directory to see Chromatica in action:

  1. Basic Gradient
  2. Radial Transparency
  3. Color Space Conversions
  4. Animated Gradients (requires matplotlib)

Contributing

We welcome contributions! Please see our Contribution Guidelines for details.

License

Chromatica is released under the MIT License. See LICENSE for details.


Project by Grayjou
GitHub | Email
Inspired by the beauty of color and light

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

chromatica-0.1.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

chromatica-0.1.1-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file chromatica-0.1.1.tar.gz.

File metadata

  • Download URL: chromatica-0.1.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for chromatica-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2faf2284810fd963aa0f10de2f1f962a84c4cdedb3dca92ea98f983c42fb67ca
MD5 80a63d06fb442c48d2a11a29d3f587e8
BLAKE2b-256 5d24db1f9a09ea5b94b7f59a1d719a5635fa1617d62a3e96bbeee25a81e2fe87

See more details on using hashes here.

File details

Details for the file chromatica-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: chromatica-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for chromatica-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccea7613db4b59f3ac8396eff029615fa9444f415708eca9c60fea1958382564
MD5 c05206261d152e07c03a7df0ceb75bf0
BLAKE2b-256 c883618bca54799b6c1ea357d771925f188e418383e8fe0dcf2d675ad338f6de

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