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.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.polyline = function () {
45 var points = "M".concat(arguments[0] || 0, ",", arguments[1] || 0, "L");
46 for (var i = 2, ii = arguments.length - 1; i < ii; i++) {
47 points += arguments[i] + "," + arguments[++i];
49 arguments[ii].toLowerCase() == "z" && (points += "z");
50 return this.path(points);
52 Raphael.fn.polygon = function (cx, cy, r, n) {
53 n = +n < 3 || !n ? 5 : n;
54 var points = ["M", cx, cy - r, "L"],
56 for (var i = 1; i < n; i++) {
57 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)]);
60 return this.path(points);
62 Raphael.fn.line = function (x1, y1, x2, y2) {
63 return this.path(["M", x1, y1, "L", x2, y2]);
65 Raphael.fn.drawGrid = function (x, y, w, h, wv, hv, color) {
66 color = color || "#000";
67 var path = ["M", x, y, "L", x + w, y, x + w, y + h, x, y + h, x, y],
70 for (var i = 1; i < hv; i++) {
71 path = path.concat(["M", x, y + i * rowHeight, "L", x + w, y + i * rowHeight]);
73 for (var i = 1; i < wv; i++) {
74 path = path.concat(["M", x + i * columnWidth, y, "L", x + i * columnWidth, y + h]);
76 return this.path(path.join(",")).attr({stroke: color});
78 Raphael.fn.square = function (cx, cy, r) {
80 return this.rect(cx - r, cy - r, 2 * r, 2 * r);
82 Raphael.fn.triangle = function (cx, cy, r) {
84 return this.path("M".concat(cx, ",", cy, "m0-", r * .58, "l", r * .5, ",", r * .87, "-", r, ",0z"));
86 Raphael.fn.diamond = function (cx, cy, r) {
87 return this.path(["M", cx, cy - r, "l", r, r, -r, r, -r, -r, r, -r, "z"]);
89 Raphael.fn.cross = function (cx, cy, r) {
91 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"]));
93 Raphael.fn.plus = function (cx, cy, r) {
95 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"]));
97 Raphael.fn.arrow = function (cx, cy, r) {
98 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"));