29 lines
613 B
JavaScript
29 lines
613 B
JavaScript
import Color from "./color.js";
|
|
|
|
class Shape {
|
|
constructor(x, y, color) {
|
|
this._x = x;
|
|
this._y = y;
|
|
this.color = color;
|
|
}
|
|
draw(context) {
|
|
throw new Error("A pure virtual method call of a shape " + this.constructor.name);
|
|
}
|
|
|
|
static randomOptions() {
|
|
return {
|
|
x: Math.floor(Math.random() * maxX),
|
|
y: Math.floor(Math.random() * maxY),
|
|
color: Color.random()
|
|
}
|
|
}
|
|
static fromOptions(o) {
|
|
return new Shape(o.x, o.y, o.color);
|
|
}
|
|
}
|
|
|
|
const maxX = 1000;
|
|
const maxY = 1000;
|
|
|
|
export default Shape;
|