fantasy/painting/shape.js

40 lines
791 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 get maxX() {
return maxX;
}
static get maxY() {
return maxY;
}
static randomOptions() {
return {
x: Math.floor(Math.random() * this.maxX),
y: Math.floor(Math.random() * this.maxY),
color: Color.random()
}
}
static fromOptions(o) {
return new Shape(o.x, o.y, o.color);
}
static setBounding(w, h) {
maxX = w;
maxY = h;
}
}
let maxX = 1000;
let maxY = 1000;
export default Shape;