RebusCardVisualEffect.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /************************************************************************
  2. * RebusCardVisualEffect.js
  3. ************************************************************************
  4. * Copyright (c) 2021 Pedro Tonini Rosenberg Schneider.
  5. *
  6. * This file is part of Alfabetiza.
  7. *
  8. * Alfabetiza 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. * Alfabetiza 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 Alfabetiza. If not, see <https://www.gnu.org/licenses/>.
  20. *************************************************************************/
  21. class RebusCardVisualEffect extends Object2D
  22. {
  23. constructor(name)
  24. {
  25. super(name);
  26. /** @type {number} */
  27. this.glowIterations = 7;
  28. /** @type {number} */
  29. this.glowAmount = 0;
  30. }
  31. _draw( /** @type {number} */ delta, /** @type {p5.Graphics} */ db)
  32. {
  33. db.rectMode(CENTER);
  34. if (this.parent.selected)
  35. {
  36. if (!this.parent.isAnswer)
  37. {
  38. db.fill(0, 80);
  39. db.rect(0, 0, 300, 400, 10, 10);
  40. }
  41. else
  42. {
  43. db.noFill();
  44. this.glowAmount = min(1.0, this.glowAmount + 0.03);
  45. for (let i = 0; i < this.glowIterations; i++)
  46. {
  47. db.stroke(255, 255, 100, this.glowAmount * 200 / (this.glowIterations + 1 - i));
  48. db.strokeWeight((this.glowIterations - i) * 6);
  49. db.rect(0, 0, 300, 400, 10);
  50. }
  51. }
  52. }
  53. }
  54. }