Plugins folder
[raphael] / plugins / raphael.primitives.js
1 Raphael.fn.star = function (cx, cy, rout, rin, n) {
2     rin = rin || rout * .5;
3     n = +n < 3 || !n ? 5 : n;
4     var points = ["M", cx, cy + rin, "L"],
5         R;
6     for (var i = 1; i < n * 2; i++) {
7         R = i % 2 ? rout : rin;
8         points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
9     }
10     points.push("z");
11     return this.path(points);
12 };
13 Raphael.fn.flower = function (cx, cy, rout, rin, n) {
14     rin = rin || rout * .5;
15     n = +n < 3 || !n ? 5 : n;
16     var points = ["M", cx, cy + rin, "Q"],
17         R;
18     for (var i = 1; i < n * 2 + 1; i++) {
19         R = i % 2 ? rout : rin;
20         points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
21     }
22     points.push("z");
23     return this.path(points);
24 };
25 Raphael.fn.spike = function (cx, cy, rout, rin, n) {
26     rin = rin || rout * .5;
27     n = +n < 3 || !n ? 5 : n;
28     var points = ["M", cx, cy - rout, "Q"],
29         R;
30     for (var i = 1; i < n * 2 + 1; i++) {
31         R = i % 2 ? rin : rout;
32         points = points.concat([cx + R * Math.sin(i * Math.PI / n - Math.PI), cy + R * Math.cos(i * Math.PI / n - Math.PI)]);
33     }
34     points.push("z");
35     return this.path(points);
36 };
37 Raphael.fn.polygon = function (cx, cy, r, n) {
38     n = +n < 3 || !n ? 5 : n;
39     var points = ["M", cx, cy - r, "L"],
40         R;
41     for (var i = 1; i < n; i++) {
42         points = points.concat([cx + r * Math.sin(i * Math.PI * 2 / n - Math.PI), cy + r * Math.cos(i * Math.PI * 2 / n - Math.PI)]);
43     }
44     points.push("z");
45     return this.path(points);
46 };
47 Raphael.fn.line = function (x1, y1, x2, y2) {
48     return this.path(["M", x1, y1, "L", x2, y2]);
49 };