Flat, round, designer-friendly pseudo-3D engine for canvas & SVG
1/**
2 * Ellipse
3 */
4
5( function( root, factory ) {
6 // module definition
7 if ( typeof module == 'object' && module.exports ) {
8 // CommonJS
9 module.exports = factory( require('./shape') );
10 } else {
11 // browser global
12 var Zdog = root.Zdog;
13 Zdog.Ellipse = factory( Zdog.Shape );
14 }
15
16}( this, function factory( Shape ) {
17
18var Ellipse = Shape.subclass({
19 diameter: 1,
20 width: undefined,
21 height: undefined,
22 quarters: 4,
23 closed: false,
24});
25
26Ellipse.type = 'Ellipse';
27
28Ellipse.prototype.setPath = function() {
29 var width = this.width != undefined ? this.width : this.diameter;
30 var height = this.height != undefined ? this.height : this.diameter;
31 var x = width/2;
32 var y = height/2;
33 this.path = [
34 { x: 0, y: -y },
35 { arc: [ // top right
36 { x: x, y: -y },
37 { x: x, y: 0 },
38 ] },
39 ];
40 // bottom right
41 if ( this.quarters > 1 ) {
42 this.path.push({ arc: [
43 { x: x, y: y },
44 { x: 0, y: y },
45 ] });
46 }
47 // bottom left
48 if ( this.quarters > 2 ) {
49 this.path.push({ arc: [
50 { x: -x, y: y },
51 { x: -x, y: 0 },
52 ] });
53 }
54 // top left
55 if ( this.quarters > 3 ) {
56 this.path.push({ arc: [
57 { x: -x, y: -y },
58 { x: 0, y: -y },
59 ] });
60 }
61};
62
63return Ellipse;
64
65} ) );