class Triangle { constructor(radius, angle = 0) { this.radius = radius this.angle = angle this.a = new Point(0, -radius).multiplyWith(getRotationMatrix(angle)) this.b = this.a.multiplyWith(getRotationMatrix(120)) this.c = this.a.multiplyWith(getRotationMatrix(240)) } drawAt(context, color, centerPoint = new Point(0, 0)) { context.strokeStyle = color context.beginPath() context.moveTo(...this.a.translateBy(centerPoint).coordinates) context.lineTo(...this.b.translateBy(centerPoint).coordinates) context.lineTo(...this.c.translateBy(centerPoint).coordinates) context.closePath() context.stroke() } cloneAndRotateBy(angle) { return new Triangle(radius, this.angle + angle) } rotateBy(angle) { this.angle = (this.angle + angle >= 360) ? this.angle + angle - 360 : this.angle + angle const rotation = getRotationMatrix(angle) this.a = this.a.multiplyWith(rotation) this.b = this.b.multiplyWith(rotation) this.c = this.c.multiplyWith(rotation) } }