Color.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /************************************************************************
  2. * Color.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Pandora.
  7. *
  8. * Pandora is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Pandora is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Pandora. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. /**
  22. * This {@code Color} class provides an interface to store a color as a component to
  23. * any GameObject.
  24. *
  25. * @author Pedro Schneider
  26. *
  27. * @class
  28. */
  29. class Color
  30. {
  31. /**
  32. * Initializes a Color with the given parameters.
  33. *
  34. * @param {number(0, 255)} r
  35. * @param {number(0, 255)} g
  36. * @param {number(0, 255)} b
  37. * @param {number(0, 255)} a
  38. *
  39. * @constructor
  40. */
  41. constructor(r, g, b, a = 255)
  42. {
  43. this.r = r;
  44. this.g = g;
  45. this.b = b;
  46. this.a = a;
  47. this.p5Color = color(this.r, this.g, this.b, this.a);
  48. }
  49. /**
  50. * Converts the color data in this Color component to a p5.Color.
  51. *
  52. * @returns {p5.Color} p5.Color representing this Color component.
  53. */
  54. getP5Color()
  55. {
  56. this.p5Color.setRed(this.r);
  57. this.p5Color.setGreen(this.g);
  58. this.p5Color.setBlue(this.b);
  59. this.p5Color.setAlpha(this.a);
  60. return this.p5Color;
  61. }
  62. }