-
Notifications
You must be signed in to change notification settings - Fork 16
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 conversion utilities for (hsv, rgb, and hex) #200
base: main
Are you sure you want to change the base?
Conversation
8f6ed56
to
bb9237f
Compare
missing run ./scripts/dependabot
./scripts/builds to setup dependabot and GitHub actions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I'm curious, why not use go-colorful?
|
||
// ColorToHex converts a color to a hex string. | ||
func ColorToHex(c color.Color) string { | ||
r, g, b, _ := c.RGBA() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a nil check
r, g, b, _ := c.RGBA() | |
if c == nil { | |
return "" | |
} | |
r, g, b, _ := c.RGBA() |
// - The hue will be rounded to the nearest degree, while the saturation and | ||
// value will be rounded to two decimal places. | ||
func ColorToHSV(c color.Color) (h, s, v float64) { | ||
r, g, b, _ := c.RGBA() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r, g, b, _ := c.RGBA() | |
if c == nil { | |
return 0, 0, 0 | |
} | |
r, g, b, _ := c.RGBA() |
c color.Color | ||
want string | ||
}{ | ||
{color.RGBA{0, 0, 0, 255}, "#000000"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{color.RGBA{0, 0, 0, 255}, "#000000"}, | |
{nil, ""}, | |
{color.RGBA{0, 0, 0, 255}, "#000000"}, |
h, s, v float64 | ||
} | ||
}{ | ||
{color.RGBA{0, 0, 0, 255}, struct{ h, s, v float64 }{0, 0, 0}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{color.RGBA{0, 0, 0, 255}, struct{ h, s, v float64 }{0, 0, 0}}, | |
{nil, struct{ h, s, v float64 }{0, 0, 0}}, | |
{color.RGBA{0, 0, 0, 255}, struct{ h, s, v float64 }{0, 0, 0}}, |
Appreciate the review. Yeah, after putting this together it occurred to me that go-colorful is probably a better choice. If it ends up doing what I need it to, I’ll close this PR without merging. |
This adds functions for converting to and from HSV.
There's also a color to hexadecimal conversion for convenience.