2022-05-21 18:12:08 +02:00
|
|
|
package colors
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// Chroma represents colorfulness.
|
2022-06-16 06:30:59 +02:00
|
|
|
type Chroma int16
|
2022-05-21 18:12:08 +02:00
|
|
|
|
|
|
|
// Percent returns the colourfulness in percent.
|
2022-06-16 06:30:59 +02:00
|
|
|
func (c Chroma) Percent() int16 {
|
2022-05-21 18:12:08 +02:00
|
|
|
if c > 100 {
|
|
|
|
return 100
|
|
|
|
} else if c < 0 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-06-16 06:30:59 +02:00
|
|
|
return int16(c)
|
2022-05-21 18:12:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hex returns the colourfulness in percent has hex string.
|
|
|
|
func (c Chroma) Hex() string {
|
|
|
|
return fmt.Sprintf("%X", c.Percent())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Uint returns the colourfulness in percent as unsigned integer.
|
|
|
|
func (c Chroma) Uint() uint {
|
|
|
|
return uint(c.Percent())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Int returns the colourfulness in percent as integer.
|
|
|
|
func (c Chroma) Int() int {
|
|
|
|
return int(c.Percent())
|
|
|
|
}
|