Pattern.js 922 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. import {Object2D} from "../Object2D.js";
  3. import {Vector2} from "../math/Vector2.js";
  4. import {Pattern2} from "../math/Pattern2.js";
  5. import {Helpers} from "../utils/Helpers.js";
  6. import {Circle} from "./Circle.js";
  7. /**
  8. * Pattern object draw a box.
  9. */
  10. function Pattern()
  11. {
  12. Object2D.call(this);
  13. /**
  14. * Image source DOM element.
  15. */
  16. this.image = document.createElement("img");
  17. /**
  18. * A DOMString indicating how to repeat the pattern image.
  19. */
  20. this.repetition = "repeat"
  21. }
  22. Pattern.prototype = Object.create(Object2D.prototype);
  23. Pattern.prototype.draw = function(context, viewport)
  24. {
  25. var width = this.box.max.x - this.box.min.x;
  26. var height = this.box.max.y - this.box.min.y;
  27. var pattern = context.createPattern(this.image, this.repetition);
  28. //pattern.setTransform();
  29. context.fillStyle = this.fillStyle;
  30. context.fillRect(this.box.min.x, this.box.min.y, width, height);
  31. };
  32. export {Pattern};