rgb.js 759 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. var utils = require('../utils')
  2. , nodes = require('../nodes')
  3. , rgba = require('./rgba');
  4. /**
  5. * Return a `RGBA` from the r,g,b channels.
  6. *
  7. * Examples:
  8. *
  9. * rgb(255,204,0)
  10. * // => #ffcc00
  11. *
  12. * rgb(#fff)
  13. * // => #fff
  14. *
  15. * @param {Unit|RGBA|HSLA} red
  16. * @param {Unit} green
  17. * @param {Unit} blue
  18. * @return {RGBA}
  19. * @api public
  20. */
  21. function rgb(red, green, blue){
  22. switch (arguments.length) {
  23. case 1:
  24. utils.assertColor(red);
  25. var color = red.rgba;
  26. return new nodes.RGBA(
  27. color.r
  28. , color.g
  29. , color.b
  30. , 1);
  31. default:
  32. return rgba(
  33. red
  34. , green
  35. , blue
  36. , new nodes.Unit(1));
  37. }
  38. }
  39. rgb.params = ['red', 'green', 'blue'];
  40. module.exports = rgb;