fantasy/painting/circle.js

27 lines
552 B
JavaScript

import Shape from "./shape.js";
class Circle extends Shape {
constructor(x, y, color, r) {
super(x, y, color);
this._r = r;
}
draw(ctx) {
ctx.beginPath();
ctx.arc(this._x, this._y, this._r, 0, Math.PI * 2);
ctx.fill();
}
static randomOptions() {
let opts = super.randomOptions();
opts.r = Math.floor(Math.random() * (this.maxY / 2));
return opts;
}
static fromOptions(o) {
return new Circle(o.x, o.y, o.color, o.r);
}
}
export default Circle;