mirror of
https://codeberg.org/Codeberg/avatars.git
synced 2023-08-10 21:12:50 +03:00
brighterThan
This commit is contained in:
parent
88ab3449de
commit
5fffca7b9c
40
main.go
40
main.go
@ -166,26 +166,19 @@ func (c *HSV) to_rgb() *RGB {
|
||||
return f2rgb(0, 0, 0)
|
||||
}
|
||||
|
||||
func add255(x uint8, y uint8) uint8 {
|
||||
if x < 255-y {
|
||||
return x + y
|
||||
func (c *RGB) brighterThan(ref RGB, delta uint8) string {
|
||||
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)
|
||||
}
|
||||
return 255
|
||||
primary.v = secondary.v + delta_f
|
||||
if primary.v > 360 {
|
||||
primary.v = 360
|
||||
}
|
||||
|
||||
func sub255(x uint8, y uint8) uint8 {
|
||||
if x > y {
|
||||
return x - y
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func (c *RGB) brighterOrDarkerThan(ref RGB, delta uint8) string {
|
||||
/* XXX FIXME: THIS IS PROBABLY NOT CORRECT. Need to look into original implementation. */
|
||||
if true {
|
||||
return fmt.Sprintf("#%02x%02x%02x", add255(c.r, delta), add255(c.g, delta), add255(c.b, delta))
|
||||
}
|
||||
return ref.darkerThan(ref, delta)
|
||||
c = primary.to_rgb()
|
||||
return fmt.Sprintf("#%02x%02x%02x", c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
func (c *RGB) darkerThan(ref RGB, delta uint8) string {
|
||||
@ -203,6 +196,17 @@ func (c *RGB) darkerThan(ref RGB, delta uint8) string {
|
||||
return fmt.Sprintf("#%02x%02x%02x", c.r, c.g, c.b)
|
||||
}
|
||||
|
||||
func (c *RGB) brighterOrDarkerThan(ref RGB, delta uint8) string {
|
||||
primary := c.to_hsv()
|
||||
secondary := ref.to_hsv()
|
||||
|
||||
if primary.v <= secondary.v {
|
||||
return c.darkerThan(ref, delta)
|
||||
} else {
|
||||
return c.brighterThan(ref, delta)
|
||||
}
|
||||
}
|
||||
|
||||
func (c RGB) withAlpha(alpha float64) string {
|
||||
return fmt.Sprintf("#%02x%02x%02x%02x", c.r, c.g, c.b, uint8(255*alpha))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user