2 * Raphael Primitives Plugin 0.2
4 * Copyright (c) 2009 Dmitry Baranovskiy (http://raphaeljs.com)
5 * Licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) license.
8 Raphael.fn.g.star = function (cx, cy, r, r2, rays) {
11 var points = ["M", cx, cy + r2, "L"],
13 for (var i = 1; i < rays * 2; i++) {
15 points = points.concat([(cx + R * Math.sin(i * Math.PI / rays)), (cy + R * Math.cos(i * Math.PI / rays))]);
18 return this.path(points.join());
20 Raphael.fn.flower = function (cx, cy, rout, rin, n) {
21 rin = rin || rout * .5;
22 n = +n < 3 || !n ? 5 : n;
23 var points = ["M", cx, cy + rin, "Q"],
25 for (var i = 1; i < n * 2 + 1; i++) {
26 R = i % 2 ? rout : rin;
27 points = points.concat([+(cx + R * Math.sin(i * Math.PI / n)).toFixed(3), +(cy + R * Math.cos(i * Math.PI / n)).toFixed(3)]);
30 return this.path(points);
32 Raphael.fn.spike = function (cx, cy, rout, rin, n) {
33 rin = rin || rout * .5;
34 n = +n < 3 || !n ? 5 : n;
35 var points = ["M", cx, cy - rout, "Q"],
37 for (var i = 1; i < n * 2 + 1; i++) {
38 R = i % 2 ? rin : rout;
39 points = points.concat([cx + R * Math.sin(i * Math.PI / n - Math.PI), cy + R * Math.cos(i * Math.PI / n - Math.PI)]);
42 return this.path(points);
44 Raphael.fn.polygon = function (cx, cy, r, n) {
45 n = +n < 3 || !n ? 5 : n;
46 var points = ["M", cx, cy - r, "L"],
48 for (var i = 1; i < n; i++) {
49 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)]);
52 return this.path(points);
54 Raphael.fn.line = function (x1, y1, x2, y2) {
55 return this.path(["M", x1, y1, "L", x2, y2]);
57 Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
58 color = color || "#000";
59 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
62 for (var i = 1; i < hv; i++) {
63 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
65 for (var i = 1; i < wv; i++) {
66 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
68 return this.path(path.join(",")).attr({stroke: color});
70 Raphael.fn.square = function (cx, cy, r) {
72 return this.rect(cx - r, cy - r, 2 * r, 2 * r);
74 Raphael.fn.triangle = function (cx, cy, r) {
76 return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z"));
78 Raphael.fn.diamond = function (cx, cy, r) {
79 return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]);
81 Raphael.fn.cross = function (cx, cy, r) {
83 return this.path("M".concat(cx - r, ",", cy, "l", [-r, -r, r, -r, r, r, r, -r, r, r, -r, r, r, r, -r, r, -r, -r, -r, r, -r, -r, "z"]));
85 Raphael.fn.plus = function (cx, cy, r) {
87 return this.path("M".concat(cx - r / 2, ",", cy - r / 2, "l", [0, -r, r, 0, 0, r, r, 0, 0, r, -r, 0, 0, r, -r, 0, 0, -r, -r, 0, 0, -r, "z"]));
89 Raphael.fn.g.arrow = function (cx, cy, r) {
90 return this.path("M".concat(cx - r * .7, ",", cy - r * .4, "l", [r * .6, 0, 0, -r * .4, r, r * .8, -r, r * .8, 0, -r * .4, -r * .6, 0], "z"));