You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

color.go 533 B

1234567891011121314151617181920212223242526
  1. package util
  2. import (
  3. "fmt"
  4. "image/color"
  5. "math"
  6. "math/rand"
  7. )
  8. func mixChannel(a uint8, b uint8, t float64) uint8 {
  9. i := (1-t)*float64(a)*float64(a) + t*float64(b)*float64(b)
  10. return uint8(math.Sqrt(i))
  11. }
  12. func MixColor(c1 color.RGBA, c2 color.RGBA, t float64) color.RGBA {
  13. res := color.RGBA{
  14. R: mixChannel(c1.R, c2.R, t),
  15. G: mixChannel(c1.G, c2.G, t),
  16. B: mixChannel(c1.B, c2.B, t),
  17. }
  18. return res
  19. }
  20. func GetRandomColor() string {
  21. return fmt.Sprintf("rgb(%d,%d,%d)", rand.Intn(256), rand.Intn(256), rand.Intn(256))
  22. }

基于Casbin的开源AI领域知识库平台

Contributors (1)