colorcycle


Namecolorcycle JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/krishnatadi/colorcycle-python
SummaryColorCycle 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.
upload_time2024-11-10 06:32:05
maintainerNone
docs_urlNone
authorKrishna Tadi
requires_python>=3.6
licenseMIT
keywords "color" "color conversion" "hex to rgb" "rgb to hex" "hex to hsl" "rgb to hsl" "hsl to rgb" "hsl to hex" "color parser" "random color" "web development" "design" "javascript" "css colors" "hex color" "rgb color" "hsl color" "colorcycle" "frontend tools" "color utilities" "color manipulation" "color names" "color library" "web design" "frontend development"
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
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.




``` python
# 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.
``` python
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".
``` python
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%.
``` python
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%.
``` python
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).
``` python
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".
``` python
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.
``` python
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.
``` python
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](https://www.npmjs.com/package/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](https://github.com/krishnatadi/colorcycle-python/issues). We actively monitor and respond to community feedback.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/krishnatadi/colorcycle-python",
    "name": "colorcycle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "\"color\", \"color conversion\", \"hex to rgb\", \"rgb to hex\", \"hex to hsl\", \"rgb to hsl\", \"hsl to rgb\", \"hsl to hex\", \"color parser\", \"random color\", \"web development\", \"design\", \"javascript\", \"css colors\", \"hex color\", \"rgb color\", \"hsl color\", \"colorcycle\", \"frontend tools\", \"color utilities\", \"color manipulation\", \"color names\", \"color library\", \"web design\", \"frontend development\"",
    "author": "Krishna Tadi",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/49/4e/667d588a8276995f8566792449a21ea51114daa1b6f24a1150fbffe8978b/colorcycle-1.1.0.tar.gz",
    "platform": null,
    "description": "# ColorCycle - Random Color Generator\r\n\r\n**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.\r\n\r\n\r\n\r\n## Installation\r\n\r\nTo install this package:\r\n\r\n```bash\r\npip install colorcycle\r\n```\r\n\r\n\r\n\r\n## Features\r\n\r\n- **Color Format Conversion**: Convert between HEX, RGB, and HSL color formats.\r\n- **Random Color Generation**: Generate random colors in HEX format for UI elements and design projects.\r\n- **Color Name Parsing**: Parse common color names (e.g., \"red\", \"blue\", \"magenta\") into their corresponding HEX, RGB, and HSL values.\r\n- **Color Brightness Adjustment**: Easily adjust the brightness of any color by a specified percentage.\r\n- **Web Safe Color Palette**: Get the closest web-safe color palette for any input color.\r\n- **Color Contrast Calculation**: Calculate the contrast ratio between two colors, useful for ensuring accessibility (WCAG compliance).\r\n- **Color Scheme Generation**: Automatically generate color schemes such as monochromatic, complementary, triadic, and analogous from a base color.\r\n\r\n\r\n\r\n## Color Conversion Functions\r\n\r\nThis 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.\r\n\r\n| **Method**                  | **Description**                                                                                                                                 | **Example**                                                         |\r\n|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|\r\n| `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')` \u00e2\u2020\u2019 `hsl(9, 100%, 60%)`                      |\r\n| `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')` \u00e2\u2020\u2019 `rgb(255, 87, 51)`                       |\r\n| `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%)')` \u00e2\u2020\u2019 `rgb(255, 87, 51)`             |\r\n| `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%)')` \u00e2\u2020\u2019 `#FF5733`                       |\r\n| `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)')` \u00e2\u2020\u2019 `#FF5733`                        |\r\n| `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)')` \u00e2\u2020\u2019 `hsl(9, 100%, 60%)`              |\r\n| `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')` \u00e2\u2020\u2019 `{'color_name': 'red', 'hex': '#FF0000', 'rgb': 'rgb(255, 0, 0)', 'hsl': 'hsl(0, 100%, 50%)'}` |\r\n| `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()` \u00e2\u2020\u2019 `{'hsl': 'hsl(180, 50%, 60%)', 'rgb': 'rgb(128, 255, 255)', 'hex': '#80FFFF'}` |\r\n\r\n---\r\n\r\n### Additional Notes\r\n\r\n- 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`.\r\n- 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.\r\n\r\n\r\n\r\n\r\n``` python\r\n# Importing functions from the colorcycle package\r\nfrom colorcycle import (\r\n    hex_to_rgb,\r\n    rgb_to_hex,\r\n    rgb_to_hsl,\r\n    hex_to_hsl,\r\n    hsl_to_rgb,\r\n    hsl_to_hex,\r\n    color_parser,\r\n    generate_random_color\r\n)\r\n```\r\n\r\n\r\n### 1. Convert HEX to RGB\r\nConverts 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.\r\n``` python\r\nprint(\"1 HEX to RGB:\")\r\nhex_color = \"#ff5733\"\r\nprint(f\"HEX: {hex_color} -> RGB: {hex_to_rgb(hex_color)}\")\r\n```\r\n\r\n### 2. Convert RGB to HEX\r\nConverts an RGB object to a HEX color. We convert the RGB values rgb(255, 87, 51) to the HEX color \"#FF5733\".\r\n``` python\r\nprint(\"\\n2 RGB to HEX:\")\r\nrgb_color = 'rgb(255, 87, 51)'\r\nprint(f\"RGB {rgb_color} -> HEX {rgb_to_hex(rgb_color)}\")\r\n```\r\n\r\n### 3. Convert RGB to HSL\r\nConverts an RGB object to an HSL object. We convert the RGB color hsl(255, 87%, 51%) to HSL values: Hue = 9\u00c2\u00b0, Saturation = 100%, Lightness = 60%.\r\n``` python\r\nprint(\"\\n3 RGB to HSL:\")\r\nprint(f\"RGB {rgb_color} -> HSL {rgb_to_hsl(rgb_color)}\")\r\n```\r\n\r\n### 4. Convert HEX to HSL\r\nConverts a HEX color to an HSL object. We convert the HEX color \"#FF5733\" to HSL values, where H is 9\u00c2\u00b0, S is 100%, and L is 60%.\r\n``` python\r\nprint(\"\\n4 HEX to HSL:\")\r\nprint(f\"HEX {hex_color} -> HSL {hex_to_hsl(hex_color)}\")\r\n```\r\n\r\n### 5. Convert HSL to RGB\r\nConverts an HSL object to an RGB object. We convert the HSL color hsl(9, 100%, 60%) to the RGB color rgb(255, 87, 51).\r\n``` python\r\nprint(\"\\n5 HSL to RGB:\")\r\nhsl_color = 'hsl(11, 100%, 60%)'  # Assuming (H, S, L) format\r\nprint(f\"HSL {hsl_color} -> RGB {hsl_to_rgb(hsl_color)}\")\r\n```\r\n\r\n### 6. Convert HSL to HEX\r\nConverts an HSL object to a HEX color. We convert the HSL color hsl(9, 100%, 60%) to the HEX color \"#FF5733\".\r\n``` python\r\nprint(\"\\n6 HSL to HEX:\")\r\nprint(f\"HSL {hsl_color} -> HEX {hsl_to_hex(hsl_color)}\")\r\n```\r\n\r\n### 7. Color Parser (Identify color name and provide RGB, HEX, and HSL values)\r\nGenerates a random RGB, HEX and HSL color.\r\n``` python\r\nprint(\"\\n7 Color Parser:\")\r\ncolor_name = \"light blue\"  # Replace with any color name\r\ncolor_data = color_parser(color_name)\r\nprint(color_data)\r\n```\r\n\r\n### 8. Generate a Random Color (RGB, HEX, HSL)\r\nParses 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.\r\n``` python\r\nprint(\"\\n8. Random Color Generator:\")\r\nrandom_color = generate_random_color()\r\nprint(f\"{random_color}\")\r\n\r\n```\r\n\r\n\r\n## Compatibility and Framework Support\r\n`ColorCycle` is lightweight and framework-agnostic, but it works seamlessly with modern Python and JavaScript frameworks [pip install colorcycle](https://www.npmjs.com/package/colorcycle) like React, Vue.js, Angular, and Svelte.\r\n\r\n\r\n## Community and Ecosystem\r\n\r\nBy 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.\r\n\r\n- **GitHub Discussions**: Share use cases, report bugs, and suggest features.\r\n\r\nWe'd love to hear from you and see how you're using **ColorCycle** in your projects!\r\n\r\n\r\n## Issues and Feedback\r\nFor issues, feedback, and feature requests, please open an issue on our [GitHub Issues page](https://github.com/krishnatadi/colorcycle-python/issues). We actively monitor and respond to community feedback.\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "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.",
    "version": "1.1.0",
    "project_urls": {
        "Documentation": "https://github.com/krishnatadi/colorcycle-python#readme",
        "Homepage": "https://github.com/krishnatadi/colorcycle-python",
        "Issue Tracker": "https://github.com/krishnatadi/colorcycle-python/issues",
        "Source": "https://github.com/krishnatadi/colorcycle-python"
    },
    "split_keywords": [
        "\"color\"",
        " \"color conversion\"",
        " \"hex to rgb\"",
        " \"rgb to hex\"",
        " \"hex to hsl\"",
        " \"rgb to hsl\"",
        " \"hsl to rgb\"",
        " \"hsl to hex\"",
        " \"color parser\"",
        " \"random color\"",
        " \"web development\"",
        " \"design\"",
        " \"javascript\"",
        " \"css colors\"",
        " \"hex color\"",
        " \"rgb color\"",
        " \"hsl color\"",
        " \"colorcycle\"",
        " \"frontend tools\"",
        " \"color utilities\"",
        " \"color manipulation\"",
        " \"color names\"",
        " \"color library\"",
        " \"web design\"",
        " \"frontend development\""
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a93f7d7e123792a393d2836901c4ca7c7e5c2f5ab16e5f25f201443b7b9e2e78",
                "md5": "c8457b7fae13935255cfa292bd1d22cc",
                "sha256": "baa5fa0027cdd8c04b4584fb6f3962ec124b8ec1f9f5c831553dda332e4e5bda"
            },
            "downloads": -1,
            "filename": "colorcycle-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c8457b7fae13935255cfa292bd1d22cc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 13562,
            "upload_time": "2024-11-10T06:32:04",
            "upload_time_iso_8601": "2024-11-10T06:32:04.105817Z",
            "url": "https://files.pythonhosted.org/packages/a9/3f/7d7e123792a393d2836901c4ca7c7e5c2f5ab16e5f25f201443b7b9e2e78/colorcycle-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "494e667d588a8276995f8566792449a21ea51114daa1b6f24a1150fbffe8978b",
                "md5": "1b8a0b0895b746b27aa2ece124592ff1",
                "sha256": "0da265a21045ffa348aa6f3fc775d9b6a452c721fa87e1e9e1e8ca170eaf78ad"
            },
            "downloads": -1,
            "filename": "colorcycle-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "1b8a0b0895b746b27aa2ece124592ff1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 16066,
            "upload_time": "2024-11-10T06:32:05",
            "upload_time_iso_8601": "2024-11-10T06:32:05.942530Z",
            "url": "https://files.pythonhosted.org/packages/49/4e/667d588a8276995f8566792449a21ea51114daa1b6f24a1150fbffe8978b/colorcycle-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-10 06:32:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "krishnatadi",
    "github_project": "colorcycle-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "colorcycle"
}
        
Elapsed time: 0.35690s