Shape2D.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /************************************************************************
  2. * Shape2D.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. class Shape2D extends Object2D
  22. {
  23. constructor(name, shapeType = null, shape = null)
  24. {
  25. super(name);
  26. this.shapeType = shapeType;
  27. this.shape = shape;
  28. this.shapeMode = CORNER;
  29. this.fillColor = color(255);
  30. this.noFill = false;
  31. this.strokeWeight = 1;
  32. this.strokeColor = color(0);
  33. this.noStroke = false;
  34. }
  35. draw(delta)
  36. {
  37. push();
  38. translate(this.position.x, this.position.y);
  39. rotate(this.rotationDegrees);
  40. scale(this.scale.x, this.scale.y);
  41. fill(this.fillColor);
  42. strokeWeight(this.strokeWeight)
  43. stroke(this.strokeColor);
  44. if (this.noFill) noFill();
  45. if (this.noStroke) noStroke();
  46. switch (this.shapeType)
  47. {
  48. case SHAPES.RECT:
  49. rectMode(this.shapeMode);
  50. rect(0, 0, this.shape.w, this.shape.h);
  51. break;
  52. case SHAPES.ELLIPSE:
  53. ellipseMode(this.shapeMode);
  54. ellipse(0, 0, this.shape.rx, this.shape.ry);
  55. }
  56. this._draw(delta);
  57. for (let i = 0; i < this.children.length; i++)
  58. this.children[i].draw(delta);
  59. pop()
  60. }
  61. }