|
326
|
1 |
|
|
|
2 |
define([], function () { |
|
|
3 |
'use strict'; |
|
|
4 |
|
|
|
5 |
/* ShapeBuilder Begin */ |
|
|
6 |
|
|
|
7 |
var builders = { |
|
|
8 |
"circle":{ |
|
|
9 |
getShape: function() { |
|
|
10 |
return new paper.Path.Circle([0, 0], 1); |
|
|
11 |
}, |
|
|
12 |
getImageShape: function(center, radius) { |
|
|
13 |
return new paper.Path.Circle(center, radius); |
|
|
14 |
} |
|
|
15 |
}, |
|
|
16 |
"rectangle":{ |
|
|
17 |
getShape: function() { |
|
|
18 |
return new paper.Path.Rectangle([-2, -2], [2, 2]); |
|
|
19 |
}, |
|
|
20 |
getImageShape: function(center, radius) { |
|
|
21 |
return new paper.Path.Rectangle([-radius, -radius], [radius*2, radius*2]); |
|
|
22 |
} |
|
|
23 |
}, |
|
|
24 |
"ellipse":{ |
|
|
25 |
getShape: function() { |
|
|
26 |
return new paper.Path.Ellipse(new paper.Rectangle([-2, -1], [2, 1])); |
|
|
27 |
}, |
|
|
28 |
getImageShape: function(center, radius) { |
|
|
29 |
return new paper.Path.Ellipse(new paper.Rectangle([-radius, -radius/2], [radius*2, radius])); |
|
|
30 |
} |
|
|
31 |
}, |
|
|
32 |
"polygon":{ |
|
|
33 |
getShape: function() { |
|
|
34 |
return new paper.Path.RegularPolygon([0, 0], 6, 1); |
|
|
35 |
}, |
|
|
36 |
getImageShape: function(center, radius) { |
|
|
37 |
return new paper.Path.RegularPolygon([0, 0], 6, radius); |
|
|
38 |
} |
|
|
39 |
}, |
|
|
40 |
"diamond":{ |
|
|
41 |
getShape: function() { |
|
|
42 |
var d = new paper.Path.Rectangle([-2, -2], [2, 2]); |
|
|
43 |
d.rotate(45); |
|
|
44 |
return d; |
|
|
45 |
}, |
|
|
46 |
getImageShape: function(center, radius) { |
|
|
47 |
var d = new paper.Path.Rectangle([-radius, -radius], [radius*2, radius*2]); |
|
|
48 |
d.rotate(45); |
|
|
49 |
return d; |
|
|
50 |
} |
|
|
51 |
}, |
|
|
52 |
"star":{ |
|
|
53 |
getShape: function() { |
|
|
54 |
return new paper.Path.Star([0, 0], 8, 1, 0.7); |
|
|
55 |
}, |
|
|
56 |
getImageShape: function(center, radius) { |
|
|
57 |
return new paper.Path.Star([0, 0], 8, radius*1, radius*0.7); |
|
|
58 |
} |
|
|
59 |
}, |
|
327
|
60 |
"svg": function(path){ |
|
|
61 |
return { |
|
|
62 |
getShape: function() { |
|
|
63 |
return new paper.Path(path); |
|
|
64 |
}, |
|
|
65 |
getImageShape: function(center, radius) { |
|
|
66 |
// No calcul for the moment |
|
|
67 |
return new paper.Path(); |
|
|
68 |
} |
|
328
|
69 |
}; |
|
327
|
70 |
} |
|
326
|
71 |
}; |
|
|
72 |
|
|
|
73 |
var ShapeBuilder = function (shape){ |
|
327
|
74 |
if(typeof shape==="undefined"){ |
|
|
75 |
shape = "circle"; |
|
|
76 |
} |
|
328
|
77 |
if(shape.substr(0,4)==="svg:"){ |
|
|
78 |
return builders.svg(shape.substr(4)); |
|
327
|
79 |
} |
|
326
|
80 |
if(!(shape in builders)){ |
|
|
81 |
shape = "circle"; |
|
|
82 |
} |
|
|
83 |
return builders[shape]; |
|
|
84 |
}; |
|
327
|
85 |
|
|
326
|
86 |
return ShapeBuilder; |
|
|
87 |
|
|
|
88 |
}); |