Skip to main content

A Python library for creating and applying full-color, linear, and circular gradients to text with easy color management.

Project description

ColorFlow

ColorFlow is a Python library for creating stunning color gradients and applying them to text with ease. It supports both linear and circular gradients and offers comprehensive utilities for managing colors.


Features

  • Comprehensive color presets
  • Create colors using RGB, HSL, or HTML hex codes
  • Generate linear and circular gradients
  • Apply gradients to multi-line text
  • Support for color interpolation
  • Works seamlessly with ANSI-supported terminals

Installation

ColorFlow can be installed using pip:

pip install colorflow

Quick Start

Creating Colors

With ColorFlow, colors can be defined in multiple formats:

from colorflow import FromRGB, FromHTML, FromHSL

# From RGB values
blue = FromRGB(0, 0, 255)

# From HTML Hex codes
red = FromHTML("#FF0000")
short_red = FromHTML("#F00")  # Short form is supported

# From HSL (Hue, Saturation, Lightness)
green = FromHSL(120, 1.0, 0.5)

Using Presets

ColorFlow includes a rich set of predefined colors through the Presets class:

from colorflow import Presets

blue = Presets.Blue
red = Presets.Red
white = Presets.White

Applying Colors to Text

from colorflow import Presets
color = Presets.Red # Red

# Apply the color to text
colored_text = color("Hello, World!")
print(colored_text)  # Displays "Hello, World!" in red

Gradients

Linear Gradients

Linear gradients allow you to transition between multiple colors across the text.

from colorflow import ColorSequence, Presets

# Create a gradient from blue to red
gradient = ColorSequence({
    0: Presets.Blue,  # Blue
    1: Presets.Red    # Red
})

# Apply the gradient to text
gradient_text = gradient("""
This text will gradually
change from blue
to red
""")

print(gradient_text)

Directional Control

The gradient's direction can be customized using start and end points.

# Top to bottom gradient
gradient = ColorSequence({
    0: Presets.Blue,  # Blue
    1: Presets.Red    # Red
}, start=(0, 0), end=(0, 1))

# Left to right gradient
gradient = ColorSequence({
    0: Presets.Blue,  # Blue
    1: Presets.Red    # Red
}, start=(0, 0), end=(1, 0))

# Diagonal gradient
gradient = ColorSequence({
    0: Presets.Blue,  # Blue
    1: Presets.Red    # Red
}, start=(0, 0), end=(1, 1))

Circular Gradients

Circular gradients radiate color patterns outward from a center point.

# Create a circular gradient
circular_gradient = ColorSequence({
    0: Presets.Blue,
    0.5: Presets.White,
    1: Presets.Red
}, start=(0.5, 0.5), end=(0.5, 0.5), gradient_type="CIRCULAR")

# Apply the gradient to text
circular_text = circular_gradient("""
This text will have
a circular gradient
emanating from the center
""")

print(circular_text)

Example with Input

from colorflow import Presets, ColorSequence

sequence = ColorSequence({
    0: Presets.Blue,    # Blue
    0.5: Presets.White, # White
    1: Presets.Red      # Red
}, start=(0.5, 0), end=(0.5, 1), gradient_type="CIRCULAR")

input(sequence("""
██████╗  ██████╗ ██████╗ ██╗ █████╗ ██╗  ██╗
██╔══██╗██╔════╝██╔═══██╗██║██╔══██╗██║  ██║
██████╔╝██║     ██║   ██║██║╚██████║███████║
██╔═══╝ ██║     ██║   ██║██║ ╚═══██║╚════██║
██║     ╚██████╗╚██████╔╝██║ █████╔╝     ██║
╚═╝      ╚═════╝ ╚═════╝ ╚═╝ ╚════╝      ╚═╝
"""))

Coordinate System

For both linear and circular gradients:

  • start and end are normalized between (0, 0) and (1, 1):
    • (0, 0) is the top-left corner
    • (1, 1) is the bottom-right corner
    • (0.5, 0.5) is the center

License

This project is licensed under the MIT License. See the LICENSE file for details.# #\x00 \x00C\x00o\x00l\x00o\x00r\x00F\x00l\x00o\x00w\x00 \x00 \x00

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

colorflow-1.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

colorflow-1.0.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file colorflow-1.0.1.tar.gz.

File metadata

  • Download URL: colorflow-1.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for colorflow-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e0109e2ff2856877c797c891921a106b30b1579b38807f8059419b5f964f5d97
MD5 366f27e0f2de4dbb553f29344f59c715
BLAKE2b-256 ec93e9c1614842b5795d8cc80a0a5bac18a96a0083d8a9aa2d4332fde6695202

See more details on using hashes here.

Provenance

The following attestation bundles were made for colorflow-1.0.1.tar.gz:

Publisher: release.yaml on Pcoi94/ColorFlow

Attestations:

File details

Details for the file colorflow-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: colorflow-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for colorflow-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da9663449a9a681fe6895b28789a87d6d03eba1cd26ec9cca5c26675818002a4
MD5 c0fff5deea28718b68bb673b95a774bc
BLAKE2b-256 8459ef0d4c6a750a8e049b8a020964101cc7adb7dad17ef56a8b58646de6ffff

See more details on using hashes here.

Provenance

The following attestation bundles were made for colorflow-1.0.1-py3-none-any.whl:

Publisher: release.yaml on Pcoi94/ColorFlow

Attestations:

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