fantasy/painting/canvas.js

24 lines
547 B
JavaScript
Raw Normal View History

2018-11-18 18:04:50 +00:00
import Color from "./color.js";
class Canvas {
constructor() {
this.element = document.createElement("canvas");
this.element.width = 1000;
this.element.height = 1000;
this._ctx = this.element.getContext("2d");
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
setFillColor(color) {
this._ctx.fillStyle = color.rgba();
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
resetStyle() {
this._ctx.fillStyle = "";
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
draw(shape) {
this._ctx.fillStyle = shape._color.rgba();
shape.draw(this._ctx);
this.resetStyle();
}
}
export default Canvas;