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

calling Darker() on a dark color can return a lighter color #10

Open
kmanley opened this issue Nov 23, 2020 · 2 comments
Open

calling Darker() on a dark color can return a lighter color #10

kmanley opened this issue Nov 23, 2020 · 2 comments
Labels
bug Something isn't working

Comments

@kmanley
Copy link

kmanley commented Nov 23, 2020

Great library - thanks for making it. One small thing I noticed is that calling Darker() on a dark RGB color can actually return a lighter RGB color. It would be more intuitive (at least to me!) if it clamped to black. On a related note it would be useful to have helper functions like IsDarker(color1, color2) bool and GetContrast(color1, color2) in the package.

@kmanley
Copy link
Author

kmanley commented Nov 23, 2020

I fixed this in my local fork by changing Darker to

// Darker returns a darker version of the specified color
func Darker(c color.Color, percent float64) color.Color {
	col, _ := colorful.MakeColor(c)
	h, cv, l := col.Hcl()

	r, g, b := colorful.Hcl(h, cv, l-(l*percent)).Clamped().RGB255()
	return color.RGBA{r, g, b, 1}
}

I think there may be other places in gamut code where Clamped() needs to be replaced by Clamped().RGB255()

@muesli
Copy link
Owner

muesli commented Nov 27, 2020

Can you provide an example where Darker produces wrong results? I'd love to add a test for this.

@muesli muesli added the bug Something isn't working label Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants