Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 1.50 KB  |  hits: 15  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Any RaphaelJS Guru knows how to draw this image?
  2. Raphael.fn.zeroToTenArc = function (x, y, r, value) {
  3.  
  4.   var set = this.set();
  5.   var pi = Math.PI;
  6.   var cos = Math.cos;
  7.   var sin = Math.sin;
  8.   var maxValue = 10;
  9.   var t = (pi/2) * 3; //translate
  10.   var rad = (pi*2 * (maxValue-value)) / maxValue + t;
  11.   var colors = ["#F79518", "#FCE6BF", "#FFF"];
  12.  
  13.   set.push(this.circle(x, y, r).attr({ fill : colors[+!value], stroke : 0 }));
  14.  
  15.   var p = [
  16.     "M", x, y,
  17.     "l", r * cos(t), r * sin(t),
  18.     "A", r, r, 0, +(rad > pi + t), 1, x + r * cos(rad), y + r * sin(rad),
  19.     "z"
  20.   ];
  21.  
  22.   set.push(this.path(p).attr({ fill : colors[1], stroke : 0 }));
  23.  
  24.  
  25.   set.push(this.circle(x, y, r*0.7).attr({ fill : colors[2], stroke : 0 }));
  26.  
  27.   return set;
  28. };
  29.  
  30. var canvas = Raphael("hello", 300, 300);
  31. var arc = canvas.zeroToTenArc(150, 150, 30, 4.2);
  32.        
  33. Raphael.fn.zeroToTenArc = function (x, y, radius, value) {
  34.   var angle = 0;
  35.   var endAngle = (value*360)/10;
  36.   var path = "";
  37.   var clockwise = -1;
  38.   var translate = Math.PI/2;
  39.  
  40.   while(angle <= endAngle) {
  41.  
  42.     var radians= (angle/180) * Math.PI + translate;
  43.     var cx = x + Math.cos(radians) * radius;
  44.     var cy = y + Math.sin(radians) * radius * clockwise;
  45.  
  46.     path += (angle === 0) ? "M" : "L";
  47.     path += [cx,cy];
  48.     angle += 1;
  49.   }
  50.  
  51.   return this.path(path);
  52. };
  53.  
  54. var canvas = Raphael("hello", 200, 200);
  55.  
  56. canvas.zeroToTenArc(50, 50, 30, 10).attr({ stroke : "#FCE6BF", "stroke-width" : 12 });
  57. canvas.zeroToTenArc(50, 50, 30, 4.2).attr({ stroke : "#F79518", "stroke-width" : 12 });