mirror of
https://codeberg.org/Codeberg/avatars.git
synced 2023-08-10 21:12:50 +03:00
darkerThan
This commit is contained in:
parent
af248521cb
commit
cb12883b6f
16
main.go
16
main.go
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user