Circle.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. "use strict";
  2. import {Object2D} from "../Object2D.js";
  3. import {Vector2} from "../math/Vector2.js";
  4. /**
  5. * Circle object draw a circular object.
  6. */
  7. function Circle()
  8. {
  9. Object2D.call(this);
  10. /**
  11. * Radius of the circle.
  12. */
  13. this.radius = 10.0;
  14. /**
  15. * Color of the circle border line.
  16. */
  17. this.strokeStyle = "#000000";
  18. /**
  19. * Background color of the circle.
  20. */
  21. this.fillStyle = "#FFFFFF";
  22. }
  23. Circle.prototype = Object.create(Object2D.prototype);
  24. Circle.prototype.isInside = function(point)
  25. {
  26. return point.length() <= this.radius;
  27. };
  28. Circle.prototype.onPointerEnter = function(pointer, viewport)
  29. {
  30. this.fillStyle = "#CCCCCC";
  31. };
  32. Circle.prototype.onPointerLeave = function(pointer, viewport)
  33. {
  34. this.fillStyle = "#FFFFFF";
  35. };
  36. Circle.prototype.draw = function(context)
  37. {
  38. context.fillStyle = this.fillStyle;
  39. context.beginPath();
  40. context.arc(0, 0, this.radius, 0, 2 * Math.PI);
  41. context.fill();
  42. context.lineWidth = 1;
  43. context.strokeStyle = this.strokeStyle;
  44. context.beginPath();
  45. context.arc(0, 0, this.radius, 0, 2 * Math.PI);
  46. context.stroke();
  47. };
  48. export {Circle};