fantasy/painting/shape.js
2018-11-20 17:32:45 +03:00

44 lines
916 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: coloring ? Color.random() : Color.randomGray()
}
}
static fromOptions(o) {
return new Shape(o.x, o.y, o.color);
}
static setBounding(w, h) {
maxX = w;
maxY = h;
}
static setColoring(bool) {
coloring = bool !== false;
}
}
let maxX = 1000;
let maxY = 1000;
let coloring = true;
export default Shape;