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
22
main.go
22
main.go
@ -126,13 +126,13 @@ func (c *RGB) to_hsv() *HSV {
|
||||
h = 0.0
|
||||
if min != v {
|
||||
if v == r {
|
||||
h = math.Mod((g - b) / C, 6.0)
|
||||
h = math.Mod((g-b)/C, 6.0)
|
||||
}
|
||||
if v == g {
|
||||
h = (b - r) / C + 2.0
|
||||
h = (b-r)/C + 2.0
|
||||
}
|
||||
if v == b {
|
||||
h = (r - g) / C + 4.0
|
||||
h = (r-g)/C + 4.0
|
||||
}
|
||||
h *= 60.0
|
||||
if h < 0.0 {
|
||||
@ -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