-
Notifications
You must be signed in to change notification settings - Fork 0
/
Circle.js
60 lines (52 loc) · 1.47 KB
/
Circle.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
59
60
import _ from 'underscore';
import CanvasElement from '../core/CanvasElement';
import {checkOptions, RedrawProperties} from '../core/util';
@RedrawProperties([
'left', 'top', 'fill',
'fillColor', 'stroke', 'strokeColor',
'strokeThickness', 'radius',
'angle', 'lineCap'
])
class Circle extends CanvasElement {
constructor(options){
super(options);
_.defaults(options, {
fill: true,
fillColor: '#000',
stroke: true,
strokeColor: '#000',
strokeThickness: 0,
radius: 10,
rotate: 0,
angle: 360,
lineCap: 'butt'
});
this.fill = options.fill;
this.fillColor = options.fillColor;
this.stroke = options.stroke;
this.strokeColor = options.strokeColor;
this.strokeThickness = options.strokeThickness;
this.radius = options.radius;
this.rotate = options.rotate;
this.angle = options.angle;
this.lineCap = options.lineCap;
}
draw(){
this.canvas.translate(-this.radius/2, -this.radius/2);
this.canvas.lineWidth = this.strokeThickness;
this.canvas.strokeStyle = this.strokeColor;
this.canvas.fillStyle = this.fillColor;
this.canvas.lineCap = this.lineCap;
this.canvas.beginPath();
const angle = this.angle * (Math.PI/180);
this.canvas.arc(this.radius/2, this.radius/2, this.radius, 0, angle, false);
if(this.fill){
this.canvas.fill();
}
if(this.stroke){
this.canvas.stroke();
}
this.canvas.closePath();
}
}
export default Circle;