Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: color variable #2867

Merged
merged 5 commits into from
Oct 28, 2024
Merged

feat: color variable #2867

merged 5 commits into from
Oct 28, 2024

Conversation

CKY-
Copy link
Collaborator

@CKY- CKY- commented Oct 23, 2024

Description of the Change

adds color variable with conversion to and from all easy to convert formats
hsl to hex
hex to hsl
color name to any
rgb
hsv
examples:

            usage: 'color[red]',
            description: "returns '#ff0000'"

            usage: 'color[red, hex]',
            description: "returns '#ff0000'"
  
            usage: 'color[red, hexa, 255]',
            description: "returns '#ff0000ff'"

            usage: 'color[green, ahex, 255]',
            description: "returns '#ff00ff00'"

            usage: 'color[green, ahex, 20]',
            description: "returns '#2000ff00'"

            usage: 'color[red, rgb]',
            description: "returns 'rgb(255, 0, 0)'"

            usage: 'color[red, rgbp]',
            description: "returns 'rgb(100%, 0, 0)'"

            usage: 'color[#00ff00, hsl]',
            description: "returns 'hsl(0, 100%, 50%)'"

            usage: 'color[#ff00ff00, hsv, 0.5]',
            description: "returns 'hsv(0, 100%, 100%)'"

            usage: 'color[#ff00ff00, dec]',
            description: "returns decimal value"

there are many more things that can be done with this
turning RGB to hex 'color[RGB(255, 0, 0)]' returns ff0000ff

Applicable Issues

#2076

Testing

I have had and used this in a script for a very long time I am adding it to the code base at the request of @dennisrijsdijk
I use this to control my WiZ lights color from chat, my clock color, and my clouds, the clouds are in hsl and the clock is in hsv
the WiZ lights are in hsv as well but everything else is in hex8 formats.

I now need someone with Elgato Strip lights and Phillips Hue to test this.

Screenshots

@CKY- CKY- requested a review from ebiggz as a code owner October 23, 2024 22:17
@dennisrijsdijk
Copy link
Collaborator

I feel it might be helpful to add a text example of the possible usages without values. Eg, I find it very unclear what color[green, ahex, 20] does just from reading the usage

@CKY-
Copy link
Collaborator Author

CKY- commented Oct 24, 2024

@dennisrijsdijk thats in the description.

@CKY-
Copy link
Collaborator Author

CKY- commented Oct 24, 2024

The string parsing is very permissive. It is meant to make typing a color as input as easy as possible. All commas, percentages, parenthesis are optional, and most input allow either 0-1, 0%-100%, or 0-n (where n is either 100, 255, or 360 depending on the value).

HSL and HSV both require either 0%-100% or 0-1 for the S/L/V properties. The H (hue) can have values between 0%-100% or 0-360.

RGB input requires either 0-255 or 0%-100%.

Here are some examples of string input:

Hex, 8-digit (RGBA) Hex

color["#000"]
color["000"]
color["#369C"]
color["369C"]
color["#f0f0f6"]
color["f0f0f6"]
color["#f0f0f688"]
color["f0f0f688"]

RGB, RGBA

color["rgb (255, 0, 0)"]
color["rgb 255 0 0"]
color["rgba (255, 0, 0, .5)"]
color[{ r: 255, g: 0, b: 0 }]

HSL, HSLA

color["hsl(0, 100%, 50%)"]
color["hsla(0, 100%, 50%, .5)"]
color["hsl(0, 100%, 50%)"]
color["hsl 0 1.0 0.5"]
color[{ h: 0, s: 1, l: .5 }]

HSV, HSVA

color["hsv(0, 100%, 100%)"]
color["hsva(0, 100%, 100%, .5)"]
color["hsv (0 100% 100%)"]
color["hsv 0 1 1"]
color[{ h: 0, s: 100, v: 100 }]

Named

Case insenstive names are accepted, using the list of colors in the CSS spec.

color["RED"]
color["blanchedalmond"]
color["darkblue"]

the output is selected by specifying the type in the second parameter the alpha is controlled by the third parameter
color[#F00, rgb, 124]
will output rgb(255, 0, 0, 0.5)

@itsjesski
Copy link
Collaborator

Is the "needs review" tag saying that this is still in testing? I'm not going to merge until everything is good.

@dennisrijsdijk
Copy link
Collaborator

This requires testing from Elgato lights and Philips Hue before merge

@CKY-
Copy link
Collaborator Author

CKY- commented Oct 28, 2024

Is the "needs review" tag saying that this is still in testing? I'm not going to merge until everything is good.

Elgato Strip lights and Phillips Hue got changed. we can move this into v5 but I would like someone with the hardware confirm that I did not break anything.

@itsjesski itsjesski merged commit 675c04a into crowbartools:v5 Oct 28, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants