-
Notifications
You must be signed in to change notification settings - Fork 0
/
Path.js
58 lines (49 loc) · 1.34 KB
/
Path.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
52
53
54
55
56
57
58
import _ from 'underscore';
import CanvasElement from '../core/CanvasElement';
import {checkOptions, RedrawProperties} from '../core/util';
@RedrawProperties([
'left', 'top','fill',
'fillColor', 'stroke', 'strokeColor',
'strokeThickness', 'rotate', 'path'
])
class Path extends CanvasElement {
constructor(options){
super(options);
_.defaults(options, {
fill: true,
fillColor: '#000',
stroke: true,
strokeColor: '#000',
strokeThickness: 0,
rotate: 0
});
this.fill = options.fill;
this.fillColor = options.fillColor;
this.stroke = options.stroke;
this.strokeColor = options.strokeColor;
this.strokeThickness = options.strokeThickness;
this.rotate = options.rotate;
this.path = options.path;
}
draw(){
this.canvas.lineWidth = this.strokeThickness;
this.canvas.strokeStyle = this.strokeColor;
this.canvas.fillStyle = this.fillColor;
_.each(this.path, (path) => {
this.canvas.beginPath();
const position = path[0];
this.canvas.moveTo(position[0], position[1]);
for(let i = 1; i < path.length; i++){
this.canvas.lineTo(path[i][0], path[i][1]);
}
if(this.fill){
this.canvas.fill();
}
if(this.stroke){
this.canvas.stroke();
}
this.canvas.closePath();
});
}
}
export default Path;