fantasy/painting/triangle.js

37 lines
851 B
JavaScript
Raw Normal View History

import Shape from "./shape.js";
class Triangle extends Shape {
constructor(x, y, color, x1, y1, x2, y2) {
super(x, y, color);
this._x1 = x1;
this._y1 = y1;
this._x2 = x2;
this._y2 = y2;
}
draw(ctx) {
ctx.beginPath();
ctx.moveTo(this._x, this._y);
ctx.lineTo(this._x1, this._y1);
ctx.lineTo(this._x2, this._y2);
ctx.fill();
}
static randomOptions() {
let opts = super.randomOptions();
let opts1 = super.randomOptions();
let opts2 = super.randomOptions();
opts.x1 = opts1.x;
opts.y1 = opts1.y;
opts.x2 = opts2.x;
opts.y2 = opts2.y;
return opts;
}
static fromOptions(o) {
return new Triangle(o.x, o.y, o.color, o.x1, o.y1, o.x2, o.y2);
}
}
export default Triangle;