Shape2D.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. class Shape2D extends Object2D
  2. {
  3. constructor(name, shapeType = null, shape = null)
  4. {
  5. super(name);
  6. this.shapeType = shapeType;
  7. this.shape = shape;
  8. this.shapeMode = CORNER;
  9. this.fillColor = color(255);
  10. this.noFill = false;
  11. this.strokeWeight = 1;
  12. this.strokeColor = color(0);
  13. this.noStroke = false;
  14. }
  15. draw(delta)
  16. {
  17. push();
  18. translate(this.position.x, this.position.y);
  19. rotate(this.rotationDegrees);
  20. scale(this.scale.x, this.scale.y);
  21. fill(this.fillColor);
  22. strokeWeight(this.strokeWeight)
  23. stroke(this.strokeColor);
  24. if (this.noFill) noFill();
  25. if(this.noStroke) noStroke();
  26. switch (this.shapeType)
  27. {
  28. case SHAPES.RECT:
  29. rectMode(this.shapeMode);
  30. rect(this.position.x, this.position.y, this.shape.w, this.shape.h);
  31. break;
  32. case SHAPES.ELLIPSE:
  33. ellipseMode(this.shapeMode);
  34. ellipse(this.position.x, this.position.y, this.shape.rx, this.shape.ry);
  35. }
  36. this._draw(delta);
  37. for (let i = 0; i < this.children.length; i++)
  38. this.children[i].draw(delta);
  39. pop()
  40. }
  41. }