fantasy/painting/circle.js

27 lines
552 B
JavaScript
Raw Normal View History

import Shape from "./shape.js";
class Circle extends Shape {
constructor(x, y, color, r) {
super(x, y, color);
this._r = r;
}
draw(ctx) {
2018-11-19 10:00:39 +00:00
ctx.beginPath();
ctx.arc(this._x, this._y, this._r, 0, Math.PI * 2);
ctx.fill();
}
static randomOptions() {
let opts = super.randomOptions();
2018-11-19 08:02:38 +00:00
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;