|
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 }, |
|
60 }; |
|
61 |
|
62 var ShapeBuilder = function (shape){ |
|
63 if(!(shape in builders)){ |
|
64 shape = "circle"; |
|
65 } |
|
66 return builders[shape]; |
|
67 }; |
|
68 |
|
69 return ShapeBuilder; |
|
70 |
|
71 }); |