fantasy/painting/shape.js

40 lines
791 B
JavaScript
Raw Normal View History

2018-11-18 18:04:50 +00:00
import Color from "./color.js";
2018-11-18 10:07:36 +00:00
class Shape {
2018-11-18 18:04:50 +00:00
constructor(x, y, color) {
this._x = x;
this._y = y;
this.color = color;
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
draw(context) {
2018-11-18 18:14:06 +00:00
throw new Error("A pure virtual method call of a shape " + this.constructor.name);
2018-11-18 18:09:30 +00:00
}
static get maxX() {
return maxX;
}
static get maxY() {
return maxY;
}
2018-11-18 18:04:50 +00:00
static randomOptions() {
return {
x: Math.floor(Math.random() * this.maxX),
y: Math.floor(Math.random() * this.maxY),
2018-11-18 18:04:50 +00:00
color: Color.random()
}
2018-11-18 18:09:30 +00:00
}
2018-11-18 18:04:50 +00:00
static fromOptions(o) {
return new Shape(o.x, o.y, o.color);
2018-11-18 10:07:36 +00:00
}
static setBounding(w, h) {
maxX = w;
maxY = h;
}
2018-11-18 10:07:36 +00:00
}
let maxX = 1000;
let maxY = 1000;
2018-11-18 18:04:50 +00:00
2018-11-18 10:07:36 +00:00
export default Shape;