=j)return p;o=p}if(j==null)return k},cg=function(b,c){return function(d,e,f){d=bG(d);var g,h,i,j,k="",l={},m,n=0;for(var o=0,p=d.length;oe){if(c&&!l.start){m=cf(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n),k+=["C"+m.start.x,m.start.y,m.m.x,m.m.y,m.x,m.y];if(f)return k;l.start=k,k=["M"+m.x,m.y+"C"+m.n.x,m.n.y,m.end.x,m.end.y,i[5],i[6]].join(),n+=j,g=+i[5],h=+i[6];continue}if(!b&&!c){m=cf(g,h,i[1],i[2],i[3],i[4],i[5],i[6],e-n);return{x:m.x,y:m.y,alpha:m.alpha}}}n+=j,g=+i[5],h=+i[6]}k+=i.shift()+i}l.end=k,m=b?n:c?l:a.findDotsAtSegment(g,h,i[0],i[1],i[2],i[3],i[4],i[5],1),m.alpha&&(m={x:m.x,y:m.y,alpha:m.alpha});return m}},ch=cg(1),ci=cg(),cj=cg(0,1);a.getTotalLength=ch,a.getPointAtLength=ci,a.getSubpath=function(a,b,c){if(this.getTotalLength(a)-c<1e-6)return cj(a,b).end;var d=cj(a,c,1);return b?cj(d,b).end:d},b$.getTotalLength=function(){if(this.type=="path"){if(this.node.getTotalLength)return this.node.getTotalLength();return ch(this.attrs.path)}},b$.getPointAtLength=function(a){if(this.type=="path")return ci(this.attrs.path,a)},b$.getSubpath=function(b,c){if(this.type=="path")return a.getSubpath(this.attrs.path,b,c)};var ck=a.easing_formulas={linear:function(a){return a},"<":function(a){return A(a,1.7)},">":function(a){return A(a,.48)},"<>":function(a){var b=.48-a/1.04,c=w.sqrt(.1734+b*b),d=c-b,e=A(z(d),1/3)*(d<0?-1:1),f=-c-b,g=A(z(f),1/3)*(f<0?-1:1),h=e+g+.5;return(1-h)*3*h*h+h*h*h},backIn:function(a){var b=1.70158;return a*a*((b+1)*a-b)},backOut:function(a){a=a-1;var b=1.70158;return a*a*((b+1)*a+b)+1},elastic:function(a){if(a==!!a)return a;return A(2,-10*a)*w.sin((a-.075)*2*B/.3)+1},bounce:function(a){var b=7.5625,c=2.75,d;a<1/c?d=b*a*a:a<2/c?(a-=1.5/c,d=b*a*a+.75):a<2.5/c?(a-=2.25/c,d=b*a*a+.9375):(a-=2.625/c,d=b*a*a+.984375);return d}};ck.easeIn=ck["ease-in"]=ck["<"],ck.easeOut=ck["ease-out"]=ck[">"],ck.easeInOut=ck["ease-in-out"]=ck["<>"],ck["back-in"]=ck.backIn,ck["back-out"]=ck.backOut;var cl=[],cm=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,16)},cn=function(){var b=+(new Date),c=0;for(;c1&&!d.next){for(s in k)k[g](s)&&(r[s]=d.totalOrigin[s]);d.el.attr(r),cr(d.anim,d.el,d.anim.percents[0],null,d.totalOrigin,d.repeat-1)}d.next&&!d.stop&&cr(d.anim,d.el,d.next,null,d.totalOrigin,d.repeat)}}a.svg&&m&&m.paper&&m.paper.safari(),cl.length&&cm(cn)},co=function(a){return a>255?255:a<0?0:a};b$.animateWith=function(b,c,d,e,f,g){var h=d?a.animation(d,e,f,g):c,i=b.status(c);return this.animate(h).status(h,i*c.ms/h.ms)},b$.onAnimation=function(a){a?eve.on("anim.frame."+this.id,a):eve.unbind("anim.frame."+this.id);return this},cq.prototype.delay=function(a){var b=new cq(this.anim,this.ms);b.times=this.times,b.del=+a||0;return b},cq.prototype.repeat=function(a){var b=new cq(this.anim,this.ms);b.del=this.del,b.times=w.floor(x(a,0))||1;return b},a.animation=function(b,c,d,e){if(b instanceof cq)return b;if(a.is(d,"function")||!d)e=e||d||null,d=null;b=Object(b),c=+c||0;var f={},h,i;for(i in b)b[g](i)&&Q(i)!=i&&Q(i)+"%"!=i&&(h=!0,f[i]=b[i]);if(!h)return new cq(b,c);d&&(f.easing=d),e&&(f.callback=e);return new cq({100:f},c)},b$.animate=function(b,c,d,e){var f=this;if(f.removed){e&&e.call(f);return f}var g=b instanceof cq?b:a.animation(b,c,d,e);cr(g,f,g.percents[0],null,f.attr());return f},b$.setTime=function(a,b){a&&b!=null&&this.status(a,y(b,a.ms)/a.ms);return this},b$.status=function(a,b){var c=[],d=0,e,f;if(b!=null){cr(a,this,-1,y(b,1));return this}e=cl.length;for(;d.5)*2-1;i(m-.5,2)+i(n-.5,2)>.25&&(n=f.sqrt(.25-i(m-.5,2))*e+.5)&&n!=.5&&(n=n.toFixed(5)-1e-5*e)}return l}),e=e.split(/\s*\-\s*/);if(j=="linear"){var t=e.shift();t=-d(t);if(isNaN(t))return null;var u=[0,0,f.cos(a.rad(t)),f.sin(a.rad(t))],v=1/(g(h(u[2]),h(u[3]))||1);u[2]*=v,u[3]*=v,u[2]<0&&(u[0]=-u[2],u[2]=0),u[3]<0&&(u[1]=-u[3],u[3]=0)}var w=a._parseDots(e);if(!w)return null;k=k.replace(/[\(\)\s,\xb0#]/g,"_"),b.gradient&&k!=b.gradient.id&&(p.defs.removeChild(b.gradient),delete b.gradient);if(!b.gradient){s=q(j+"Gradient",{id:k}),b.gradient=s,q(s,j=="radial"?{fx:m,fy:n}:{x1:u[0],y1:u[1],x2:u[2],y2:u[3],gradientTransform:b.matrix.invert()}),p.defs.appendChild(s);for(var x=0,y=w.length;x1?G.opacity/100:G.opacity});case"stroke":G=a.getRGB(p),i.setAttribute(o,G.hex),o=="stroke"&&G[b]("opacity")&&q(i,{"stroke-opacity":G.opacity>1?G.opacity/100:G.opacity}),o=="stroke"&&d._.arrows&&("startString"in d._.arrows&&t(d,d._.arrows.startString),"endString"in d._.arrows&&t(d,d._.arrows.endString,1));break;case"gradient":(d.type=="circle"||d.type=="ellipse"||c(p).charAt()!="r")&&r(d,p);break;case"opacity":k.gradient&&!k[b]("stroke-opacity")&&q(i,{"stroke-opacity":p>1?p/100:p});case"fill-opacity":if(k.gradient){H=a._g.doc.getElementById(i.getAttribute("fill").replace(/^url\(#|\)$/g,l)),H&&(I=H.getElementsByTagName("stop"),q(I[I.length-1],{"stop-opacity":p}));break};default:o=="font-size"&&(p=e(p,10)+"px");var J=o.replace(/(\-.)/g,function(a){return a.substring(1).toUpperCase()});i.style[J]=p,d._.dirty=1,i.setAttribute(o,p)}}y(d,f),i.style.visibility=m},x=1.2,y=function(d,f){if(d.type=="text"&&!!(f[b]("text")||f[b]("font")||f[b]("font-size")||f[b]("x")||f[b]("y"))){var g=d.attrs,h=d.node,i=h.firstChild?e(a._g.doc.defaultView.getComputedStyle(h.firstChild,l).getPropertyValue("font-size"),10):10;if(f[b]("text")){g.text=f.text;while(h.firstChild)h.removeChild(h.firstChild);var j=c(f.text).split("\n"),k=[],m;for(var n=0,o=j.length;n"));var $=X.getBoundingClientRect();t.W=m.w=($.right-$.left)/Y,t.H=m.h=($.bottom-$.top)/Y,t.X=m.x,t.Y=m.y+t.H/2,("x"in i||"y"in i)&&(t.path.v=a.format("m{0},{1}l{2},{1}",f(m.x*u),f(m.y*u),f(m.x*u)+1));var _=["x","y","text","font","font-family","font-weight","font-style","font-size"];for(var ba=0,bb=_.length;ba.25&&(c=e.sqrt(.25-i(b-.5,2))*((c>.5)*2-1)+.5),m=b+n+c);return o}),f=f.split(/\s*\-\s*/);if(l=="linear"){var p=f.shift();p=-d(p);if(isNaN(p))return null}var q=a._parseDots(f);if(!q)return null;b=b.shape||b.node;if(q.length){b.removeChild(g),g.on=!0,g.method="none",g.color=q[0].color,g.color2=q[q.length-1].color;var r=[];for(var s=0,t=q.length;s')}}catch(c){F=function(a){return b.createElement("<"+a+' xmlns="urn:schemas-microsoft.com:vml" class="rvml">')}}},a._engine.initWin(a._g.win),a._engine.create=function(){var b=a._getContainer.apply(0,arguments),c=b.container,d=b.height,e,f=b.width,g=b.x,h=b.y;if(!c)throw new Error("VML container not found.");var i=new a._Paper,j=i.canvas=a._g.doc.createElement("div"),k=j.style;g=g||0,h=h||0,f=f||512,d=d||342,i.width=f,i.height=d,f==+f&&(f+="px"),d==+d&&(d+="px"),i.coordsize=u*1e3+n+u*1e3,i.coordorigin="0 0",i.span=a._g.doc.createElement("span"),i.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;",j.appendChild(i.span),k.cssText=a.format("top:0;left:0;width:{0};height:{1};display:inline-block;position:relative;clip:rect(0 {0} {1} 0);overflow:hidden",f,d),c==1?(a._g.doc.body.appendChild(j),k.left=g+"px",k.top=h+"px",k.position="absolute"):c.firstChild?c.insertBefore(j,c.firstChild):c.appendChild(j),i.renderfix=function(){};return i},a.prototype.clear=function(){a.eve("clear",this),this.canvas.innerHTML=o,this.span=a._g.doc.createElement("span"),this.span.style.cssText="position:absolute;left:-9999em;top:-9999em;padding:0;margin:0;line-height:1;display:inline;",this.canvas.appendChild(this.span),this.bottom=this.top=null},a.prototype.remove=function(){a.eve("remove",this),this.canvas.parentNode.removeChild(this.canvas);for(var b in this)this[b]=typeof this[b]=="function"?a._removedFactory(b):null;return!0};var G=a.st;for(var H in E)E[b](H)&&!G[b](H)&&(G[H]=function(a){return function(){var b=arguments;return this.forEach(function(c){c[a].apply(c,b)})}}(H))}(window.Raphael)
--------------------------------------------------------------------------------
/raphael_animation.js:
--------------------------------------------------------------------------------
1 | Raphael('raphaelAnimation', 200, 200, function () {
2 | var paper = this,
3 | anim;
4 |
5 | var c = paper.circle(100, 100, 10);
6 | c.attr({
7 | fill: '#00aeef',
8 | stroke: 'none'
9 | });
10 |
11 | var r = paper.rect(60, 60, 80, 80);
12 | r.attr({
13 | 'stroke-width': 2,
14 | stroke: '#00aeef',
15 | fill: "#000",
16 | "fill-opacity": 0
17 | });
18 | r.click(function () {
19 | if (anim) {
20 | r.stop();
21 | } else {
22 | r.animate(a);
23 | }
24 | anim = !anim;
25 | });
26 |
27 | r.rotate(60);
28 |
29 | var a = Raphael.animation({transform: "...r360"}, 3000).repeat(Infinity);
30 |
31 | });
32 |
--------------------------------------------------------------------------------
/raphael_circle.js:
--------------------------------------------------------------------------------
1 | Raphael('raphaelCircle', 200, 200, function () {
2 | this.circle(100, 100, 10).attr({
3 | fill: '#00aeef',
4 | stroke: 'none'
5 | });
6 | });
--------------------------------------------------------------------------------
/raphael_gears.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Raphaël Gears
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | Gears in Raphaël
33 |
34 | Paper vs. Processing vs. Raphaël
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/raphael_gears.js:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | *
3 | * Copyright 2011 Zack Grossbart
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | *
17 | ******************************************************************************/
18 |
19 | var scale = 15;
20 | var toothSize = 28;
21 | var clockwise = false;
22 |
23 |
24 | g = {
25 | stopped: false,
26 | create: function(/*Point*/ p, /*int*/ teeth, /*string*/ c, /*int*/ speed, /*boolean*/ clockwise) {
27 |
28 | g.speed = speed;
29 | g.clockwise = clockwise;
30 |
31 | var d = teeth * scale;
32 |
33 | var outerCircle = g.paper.circle(p.x, p.y, d / 2);
34 | outerCircle.attr({
35 | fill: c,
36 | stroke: c
37 | });
38 | outerCircle.click(function() {
39 | g.stopped = !g.stopped;
40 | });
41 |
42 | var innerCircle = g.paper.circle(p.x, p.y, d / 8);
43 | innerCircle.attr({
44 | fill: 'white',
45 | stroke: 'white'
46 | });
47 | innerCircle.click(function() {
48 | g.stopped = !g.stopped;
49 | });
50 |
51 | var st = g.drawTeeth((d / 2) - 5, d / scale, c, p),
52 | an = Raphael.animation({transform: (clockwise ? "r360," : "r-360,") + [p.x, p.y]}, speed);
53 |
54 | var path = "";
55 | for (var i = 0, ii = st.length; i < ii; i++) {
56 | path += Raphael.mapPath(st[i].attr("path"), st[i].matrix);
57 | }
58 | st.remove();
59 | st = g.paper.path(path).attr({
60 | stroke: "none",
61 | fill: c
62 | });
63 |
64 | st.animate(an.repeat(Infinity));
65 | },
66 |
67 | drawTeeth: function(/*int*/ d, /*int*/ plots, /*color*/ c, /*Point*/ p) {
68 | var increase = 360 / plots;
69 | var angle = 0;
70 |
71 | var st = g.paper.set();
72 |
73 | for (var i = 0; i < plots; i++) {
74 | var tooth = g.createTooth(c);
75 | tooth.transform("t" + [p.x, p.y - (d + (toothSize / 2))] + "R" + [angle, p.x, p.y]);
76 | st.push(tooth);
77 | angle += increase;
78 | }
79 |
80 | return st;
81 | },
82 |
83 | createTooth: function(/*color*/ c) {
84 | var t2 = toothSize / 2;
85 | var path = 'M ' + (-t2 / 2 + 2) + ' ' + (-t2) + // upper left
86 | 'L ' + (t2 / 2 - 6) + ' ' + (-t2) + // upper right
87 | 'L ' + (t2 / 2) + ' ' + (-t2 + 8) + // upper right bump
88 | 'L ' + t2 + ' ' + t2 + // bottom right
89 | 'L ' + (-t2) + ' ' + t2 + // bottom left
90 | 'L ' + (-t2 + 4) + ' ' + (-t2 + 8); // upper left bump
91 | path += ' z';
92 |
93 | return g.paper.path(path).attr({
94 | fill: c,
95 | stroke: "none"
96 | });
97 | }
98 | };
99 |
100 | window.onload = function () {
101 | g.paper = Raphael('canvas', 960, 650);
102 |
103 | var back = g.paper.rect(0, 0, 960, 650);
104 | back.attr({
105 | fill: '#ececec',
106 | stroke: 'none'
107 | });
108 |
109 | back.click(function() {
110 | g.stopped = !g.stopped;
111 | });
112 |
113 | var speed = 15000;
114 |
115 | g.create({
116 | 'x': 150,
117 | 'y': 150
118 | }, 15, '#00aeef', speed, !clockwise);
119 |
120 | g.create({
121 | 'x': 295,
122 | 'y': 285
123 | }, 8, '#ee5b32', speed * (8 / 15), clockwise);
124 |
125 | g.create({
126 | 'x': 172,
127 | 'y': 587
128 | }, 32, '#F00FF0', speed * (17 / 8), !clockwise);
129 |
130 | g.create({
131 | 'x': 565,
132 | 'y': 425
133 | }, 21, '#fec01e', speed * (23.5 / 17), clockwise);
134 |
135 | g.create({
136 | 'x': 615,
137 | 'y': 165
138 | }, 11, '#157d6b', speed * (8 / 11), !clockwise);
139 |
140 | };
141 |
--------------------------------------------------------------------------------
/raphael_interaction.js:
--------------------------------------------------------------------------------
1 | jQuery(document).ready(function() {
2 | var paper = Raphael('raphaelInteraction', 200, 200);
3 | var r = paper.rect(60, 60, 80, 80);
4 | r.attr({
5 | 'fill': '#00aeef',
6 | 'stroke': '#00aeef'
7 | });
8 |
9 | var clicked = false;
10 |
11 | r.click(function() {
12 | if (clicked) {
13 | r.attr({
14 | 'fill': '#00aeef',
15 | 'stroke': '#00aeef'
16 | });
17 | } else {
18 | r.attr({
19 | 'fill': '#f00ff0',
20 | 'stroke': '#f00ff0'
21 | });
22 | }
23 | clicked = !clicked;
24 | });
25 | });
26 |
--------------------------------------------------------------------------------