mathutils.Color.py 924 B

12345678910111213141516171819202122232425262728293031
  1. import mathutils
  2. # color values are represented as RGB values from 0 - 1, this is blue
  3. col = mathutils.Color((0.0, 0.0, 1.0))
  4. # as well as r/g/b attribute access you can adjust them by h/s/v
  5. col.s *= 0.5
  6. # you can access its components by attribute or index
  7. print("Color R:", col.r)
  8. print("Color G:", col[1])
  9. print("Color B:", col[-1])
  10. print("Color HSV: %.2f, %.2f, %.2f", col[:])
  11. # components of an existing color can be set
  12. col[:] = 0.0, 0.5, 1.0
  13. # components of an existing color can use slice notation to get a tuple
  14. print("Values: %f, %f, %f" % col[:])
  15. # colors can be added and subtracted
  16. col += mathutils.Color((0.25, 0.0, 0.0))
  17. # Color can be multiplied, in this example color is scaled to 0-255
  18. # can printed as integers
  19. print("Color: %d, %d, %d" % (col * 255.0)[:])
  20. # This example prints the color as hexadecimal
  21. print("Hexadecimal: %.2x%.2x%.2x" % (int(col.r * 255), int(col.g * 255), int(col.b * 255)))