Skip to main content

ColorCycle - Random Color Generator

ColorCycle is a Python package that helps developers easily convert color formats between Hex, RGB, and HSL. This tool is ideal for designers and developers working on color management for websites, applications, and graphical projects. Simply provide a color in any of the supported formats, and ColorCycle will convert it into the others.

Installation

To install this package:

pip install colorcycle

Features

  • Color Format Conversion: Convert between HEX, RGB, and HSL color formats.
  • Random Color Generation: Generate random colors in HEX format for UI elements and design projects.
  • Color Name Parsing: Parse common color names (e.g., "red", "blue", "magenta") into their corresponding HEX, RGB, and HSL values.
  • Color Brightness Adjustment: Easily adjust the brightness of any color by a specified percentage.
  • Web Safe Color Palette: Get the closest web-safe color palette for any input color.
  • Color Contrast Calculation: Calculate the contrast ratio between two colors, useful for ensuring accessibility (WCAG compliance).
  • Color Scheme Generation: Automatically generate color schemes such as monochromatic, complementary, triadic, and analogous from a base color.

Color Conversion Functions

This document provides details for various color conversion functions that can convert between HEX, RGB, and HSL formats. Each function is described along with its usage and an example.

Method Description Example
hex_to_hsl(hex_color) Converts a HEX color code to HSL format. It accepts a string representing the HEX code (e.g., #RRGGBB) and returns a string in hsl(h, s%, l%) format. hex_to_hsl('#FF5733') → hsl(9, 100%, 60%)
hex_to_rgb(hex_color) Converts a HEX color code to RGB format. It accepts a string representing the HEX code and returns a string in rgb(r, g, b) format. hex_to_rgb('#FF5733') → rgb(255, 87, 51)
hsl_to_rgb(hsl_color) Converts an HSL color value to RGB format. It accepts a string in hsl(h, s%, l%) format and returns the RGB equivalent in rgb(r, g, b) format. hsl_to_rgb('hsl(9, 100%, 60%)') → rgb(255, 87, 51)
hsl_to_hex(hsl_color) Converts an HSL color value to HEX format. It accepts a string in hsl(h, s%, l%) format and returns the HEX equivalent as a string #RRGGBB. hsl_to_hex('hsl(9, 100%, 60%)') → #FF5733
rgb_to_hex(rgb_string) Converts an RGB color value to HEX format. It accepts a string in rgb(r, g, b) format and returns the HEX equivalent in #RRGGBB. rgb_to_hex('rgb(255, 87, 51)') → #FF5733
rgb_to_hsl(rgb_color) Converts an RGB color value to HSL format. It accepts a string in rgb(r, g, b) format and returns the HSL equivalent in hsl(h, s%, l%). rgb_to_hsl('rgb(255, 87, 51)') → hsl(9, 100%, 60%)
color_parser(color_name) Accepts a color name (e.g., "red", "blue") and returns the corresponding HEX, RGB, and HSL values based on a predefined dictionary of color names. color_parser('red') → {'color_name': 'red', 'hex': '#FF0000', 'rgb': 'rgb(255, 0, 0)', 'hsl': 'hsl(0, 100%, 50%)'}
generate_random_color() Generates a random color and returns it in HEX, RGB, and HSL formats. The generated values are random for red, green, and blue components. generate_random_color() → {'hsl': 'hsl(180, 50%, 60%)', 'rgb': 'rgb(128, 255, 255)', 'hex': '#80FFFF'}

Additional Notes

  • The functions assume valid color inputs. For example, HEX codes should be in the format #RRGGBB and RGB values should be in the range of 0-255.
  • The color_parser method relies on a predefined dictionary of color names. Ensure that this dictionary is available and properly populated with color name-to-HEX mappings.
# Importing functions from the colorcycle package
from colorcycle import (
    hex_to_rgb,
    rgb_to_hex,
    rgb_to_hsl,
    hex_to_hsl,
    hsl_to_rgb,
    hsl_to_hex,
    color_parser,
    generate_random_color
)

1. Convert HEX to RGB

Converts a HEX color to an RGB object. We convert the HEX value "#FF5733" to its RGB components: 255 for Red, 87 for Green, and 51 for Blue.

print("1 HEX to RGB:")
hex_color = "#ff5733"
print(f"HEX: {hex_color} -> RGB: {hex_to_rgb(hex_color)}")

2. Convert RGB to HEX

Converts an RGB object to a HEX color. We convert the RGB values rgb(255, 87, 51) to the HEX color "#FF5733".

print("\n2 RGB to HEX:")
rgb_color = 'rgb(255, 87, 51)'
print(f"RGB {rgb_color} -> HEX {rgb_to_hex(rgb_color)}")

3. Convert RGB to HSL

Converts an RGB object to an HSL object. We convert the RGB color hsl(255, 87%, 51%) to HSL values: Hue = 9°, Saturation = 100%, Lightness = 60%.

print("\n3 RGB to HSL:")
print(f"RGB {rgb_color} -> HSL {rgb_to_hsl(rgb_color)}")

4. Convert HEX to HSL

Converts a HEX color to an HSL object. We convert the HEX color "#FF5733" to HSL values, where H is 9°, S is 100%, and L is 60%.

print("\n4 HEX to HSL:")
print(f"HEX {hex_color} -> HSL {hex_to_hsl(hex_color)}")

5. Convert HSL to RGB

Converts an HSL object to an RGB object. We convert the HSL color hsl(9, 100%, 60%) to the RGB color rgb(255, 87, 51).

print("\n5 HSL to RGB:")
hsl_color = 'hsl(11, 100%, 60%)'  # Assuming (H, S, L) format
print(f"HSL {hsl_color} -> RGB {hsl_to_rgb(hsl_color)}")

6. Convert HSL to HEX

Converts an HSL object to a HEX color. We convert the HSL color hsl(9, 100%, 60%) to the HEX color "#FF5733".

print("\n6 HSL to HEX:")
print(f"HSL {hsl_color} -> HEX {hsl_to_hex(hsl_color)}")

7. Color Parser (Identify color name and provide RGB, HEX, and HSL values)

Generates a random RGB, HEX and HSL color.

print("\n7 Color Parser:")
color_name = "light blue"  # Replace with any color name
color_data = color_parser(color_name)
print(color_data)

8. Generate a Random Color (RGB, HEX, HSL)

Parses common color names and returns the corresponding HEX, RGB, and HSL values. This function takes the color name "red" and returns its HEX, RGB, and HSL values.

print("\n8. Random Color Generator:")
random_color = generate_random_color()
print(f"{random_color}")

Compatibility and Framework Support

ColorCycle is lightweight and framework-agnostic, but it works seamlessly with modern Python and JavaScript frameworks pip install colorcycle like React, Vue.js, Angular, and Svelte.

Community and Ecosystem

By using ColorCycle, you are joining a growing community of developers who are passionate about colors and design. We encourage you to share your experiences, ideas, and feedback on GitHub Discussions or any community platform of your choice.

  • GitHub Discussions: Share use cases, report bugs, and suggest features.

We'd love to hear from you and see how you're using ColorCycle in your projects!

Issues and Feedback

For issues, feedback, and feature requests, please open an issue on our GitHub Issues page. We actively monitor and respond to community feedback.

Metadata

Release files for colorcycle 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for colorcycle 1.1.0
File Size Uploaded Provenance
colorcycle-1.1.0.tar.gz 16.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for colorcycle 1.1.0
File Interpreter ABI Platform
colorcycle-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.6 kB

Release files / colorcycle-1.1.0.tar.gz

Download URL colorcycle-1.1.0.tar.gz
Size 16.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0da265a21045ffa348aa6f3fc775d9b6a452c721fa87e1e9e1e8ca170eaf78ad
BLAKE2b-256 checksum
How to use checksums
494e667d588a8276995f8566792449a21ea51114daa1b6f24a1150fbffe8978b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Release files / colorcycle-1.1.0-py3-none-any.whl

Download URL colorcycle-1.1.0-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
baa5fa0027cdd8c04b4584fb6f3962ec124b8ec1f9f5c831553dda332e4e5bda
BLAKE2b-256 checksum
How to use checksums
a93f7d7e123792a393d2836901c4ca7c7e5c2f5ab16e5f25f201443b7b9e2e78
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.3

Security for colorcycle 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page