fantasy/painting/shape.js

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;