31 lines
747 B
JavaScript
31 lines
747 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._x + this._width, this._y + this._height);
|
|
}
|
|
|
|
static randomOptions() {
|
|
opts = super.randomOptions();
|
|
|
|
opts.width = Math.floor(Math.random() * maxWidth);
|
|
opts.height = Math.floor(Math.random() * maxHeight);
|
|
|
|
return opts;
|
|
}
|
|
static fromOptions(o) {
|
|
return new Rectangle(o.x, o.y, o.color, o.width, o.height);
|
|
}
|
|
}
|
|
|
|
const maxWidth = 1000;
|
|
const maxHeight = 1000;
|
|
|
|
export default Rectangle;
|