-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjcl.Oval.js
55 lines (41 loc) · 1.39 KB
/
jcl.Oval.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
JCL.Oval = function(options) {
options = options || {};
this.x = options.x || 0;
this.y = options.y || 0;
this.width = options.width || 0;
this.height = options.height || 0;
this.fillStyle = options.fill || null;
this.strokeStyle = options.stroke || null;
this.lineWidth = options.thickness || 0;
this.calculate();
return this;
};
JCL.Oval.prototype = {
// calculate()
// Calculates the points required for generating the bezier curves.
calculate: function () {
this.start = new JCL.Point(this.x, this.y);
this.end = new JCL.Point(this.x + this.width, this.y + this.height);
this.mid = new JCL.Point((this.x + this.width) / 2, (this.y + this.height) / 2);
return this;
},
// center()
// Calculates the center of the oval
center: function(point) {
if (point) {
this.x = point.x - (this.width / 2);
this.y = point.y - (this.height / 2);
this.calculate();
return this;
} else {
return new JCL.Point(this.x + (this.width / 2), this.y + (this.height / 2));
}
},
// render()
// Draws the oval on the JCL.Canvas.
render: function(canvas){
if (canvas instanceof JCL.Canvas) { canvas.drawOval(this); }
else { JCL.error("Specified canvas is not an instance of JCL.Canvas."); }
return this;
}
};