fantasy/painting/shape.js

29 lines
628 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
className: "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.className);
},
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);
2018-11-18 10:07:36 +00:00
}
}
2018-11-18 18:04:50 +00:00
const maxX = 1000;
const maxY = 1000;
2018-11-18 10:07:36 +00:00
export default Shape;