fantasy/painting/canvas.js

28 lines
670 B
JavaScript

import Color from "./color.js";
class Canvas {
constructor(width, height) {
this.element = document.createElement("canvas");
this.element.width = width;
this.element.height = height;
this._ctx = this.element.getContext("2d");
}
setFillColor(color) {
this._ctx.fillStyle = color.rgba();
}
resetStyle() {
this._ctx.fillStyle = "";
}
draw(shape) {
this._ctx.fillStyle = shape.color.rgba();
shape.draw(this._ctx);
this.resetStyle();
}
resize(width, height) {
this.element.width = width;
this.element.height = height;
}
}
export default Canvas;