fantasy/painting/rectangle.js

28 lines
726 B
JavaScript
Raw Normal View History

2018-11-18 18:04:50 +00:00
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;
2018-11-18 18:09:30 +00:00
}
draw(context) {
context.fillRect(this._x, this._y, this._x + this._width, this._y + this._height);
}
2018-11-18 18:04:50 +00:00
static randomOptions() {
2018-11-18 18:16:26 +00:00
let opts = super.randomOptions();
2018-11-18 18:04:50 +00:00
opts.width = Math.floor(Math.random() * (this.maxX - opts.x));
opts.height = Math.floor(Math.random() * (this.maxY - opts.y));
2018-11-18 18:04:50 +00:00
return opts;
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
static fromOptions(o) {
return new Rectangle(o.x, o.y, o.color, o.width, o.height);
}
}
export default Rectangle;