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 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright 2023 The casbin Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package util
  15. import (
  16. "fmt"
  17. "image/color"
  18. "math"
  19. "math/rand"
  20. )
  21. func mixChannel(a uint8, b uint8, t float64) uint8 {
  22. i := (1-t)*float64(a)*float64(a) + t*float64(b)*float64(b)
  23. return uint8(math.Sqrt(i))
  24. }
  25. func MixColor(c1 color.RGBA, c2 color.RGBA, t float64) color.RGBA {
  26. res := color.RGBA{
  27. R: mixChannel(c1.R, c2.R, t),
  28. G: mixChannel(c1.G, c2.G, t),
  29. B: mixChannel(c1.B, c2.B, t),
  30. }
  31. return res
  32. }
  33. func GetRandomColor() string {
  34. return fmt.Sprintf("rgb(%d,%d,%d)", rand.Intn(256), rand.Intn(256), rand.Intn(256))
  35. }

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