darkerThan

This commit is contained in:
Codeberg 2019-05-28 12:48:54 +02:00 committed by Holger Waechtler
parent af248521cb
commit cb12883b6f

16
main.go
View File

@ -189,10 +189,18 @@ func (c *RGB) brighterOrDarkerThan(ref RGB, delta uint8) string {
}
func (c *RGB) darkerThan(ref RGB, delta uint8) string {
/* XXX FIXME: THIS IS NOT CORRECT. The original implementation does darkening in HSV space.
* cf. https://github.com/DiceBear/avatars/blob/master/packages/avatars/src/color.ts
*/
return fmt.Sprintf("#%02x%02x%02x", sub255(c.r, delta), sub255(c.g, delta), sub255(c.b, delta))
primary := c.to_hsv()
secondary := ref.to_hsv()
delta_f := float64(delta) * 1.0 / 255.0
if primary.v <= secondary.v-delta_f {
return fmt.Sprintf("#%02x%02x%02x", c.r, c.g, c.b)
}
primary.v = secondary.v - delta_f
if primary.v < 0 {
primary.v = 0
}
c = primary.to_rgb()
return fmt.Sprintf("#%02x%02x%02x", c.r, c.g, c.b)
}
func (c RGB) withAlpha(alpha float64) string {