fantasy/painting/rectangle.js

28 lines
706 B
JavaScript

import Shape from "./shape.js";
class Rectangle extends Shape {
constructor(x, y, color, width, height) {
super(x, y, color);
this._width = width;
this._height = height;
}
draw(context) {
context.fillRect(this._x, this._y, this._width, this._height);
}
static randomOptions() {
let opts = super.randomOptions();
opts.width = Math.floor(Math.random() * (this.maxX - opts.x));
opts.height = Math.floor(Math.random() * (this.maxY - opts.y));
return opts;
}
static fromOptions(o) {
return new Rectangle(o.x, o.y, o.color, o.width, o.height);
}
}
export default Rectangle;