800_color32.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from vmath import color32, rgb, rgba, vec3i
  2. a = color32(100, 200, 255, 120)
  3. assert a.r == 100
  4. assert a.g == 200
  5. assert a.b == 255
  6. assert a.a == 120
  7. assert a.with_r(255).r == 255
  8. assert a.with_g(255).g == 255
  9. assert a.with_b(255).b == 255
  10. assert a.with_a(255).a == 255 and a.with_a(255).g == a.g
  11. assert a.to_hex() == '#64c8ff78'
  12. assert color32.from_hex('#64c8ff78') == a
  13. assert color32.from_hex('#64c8ff') == a.with_a(255)
  14. assert rgb(100, 200, 255) != a
  15. assert rgba(100, 200, 255, 120 / 255) == a
  16. b = color32(75, 150, 200, 200)
  17. assert a == a and b == b
  18. assert a != b
  19. assert repr(b) == 'color32(75, 150, 200, 200)'
  20. assert color32.from_vec3i(vec3i(100, 200, 255)) == rgb(100, 200, 255)
  21. alpha = a.a / 255
  22. assert a.to_vec3i() == vec3i(int(a.r * alpha), int(a.g * alpha), int(a.b * alpha))
  23. # assert color32.alpha_blend(a, b) == color32(86, 173, 225, 162)
  24. c = rgb(100, 200, 255)
  25. assert c.ansi_fg('xxx') == '\x1b[38;2;100;200;255mxxx\x1b[0m'
  26. assert c.ansi_bg('xxx') == '\x1b[48;2;100;200;255mxxx\x1b[0m'
  27. assert color32.alpha_blend(a, None) == a