-
Notifications
You must be signed in to change notification settings - Fork 0
/
Triangle.js
51 lines (44 loc) · 1.32 KB
/
Triangle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import _ from 'underscore';
import CanvasElement from '../core/CanvasElement';
import {RedrawProperties} from '../core/util';
@RedrawProperties([
'stroke', 'strokeColor', 'strokeThickness',
'fill','fillColor', 'rotate'
])
class Triangle extends CanvasElement {
constructor(options){
super(options);
_.defaults(options, {
fill: true,
fillColor: '#000',
stroke: true,
strokeColor: '#000',
strokeThickness: 0,
rotate: 180
});
this.fill = options.fill;
this.fillColor = options.fillColor;
this.stroke = options.stroke;
this.strokeColor = options.strokeColor;
this.strokeThickness = options.strokeThickness;
this.rotate = options.rotate;
}
draw(){
this.canvas.translate(-this.width/2, -this.height/2);
this.canvas.fillStyle = this.fillColor;
this.canvas.strokeStyle = this.strokeColor;
this.canvas.lineWidth = this.strokeThickness;
this.canvas.beginPath();
this.canvas.moveTo(this.strokeThickness/2, this.strokeThickness/2);
this.canvas.lineTo(this.width-this.strokeThickness/2, this.strokeThickness/2);
this.canvas.lineTo(this.width/2, this.height-this.strokeThickness/2);
this.canvas.closePath();
if(this.fill){
this.canvas.fill();
}
if(this.stroke){
this.canvas.stroke();
}
}
}
export default Triangle;