raphael js中的弧形像一个规格

时间:2013-09-03 08:50:49

标签: javascript raphael

我的圈子从12点钟开始。但我需要从7开始到5结束。始终水平启动,但我需要垂直启动。还有如何像阴影等一样添加效果。

var amount = ("80");


var archtype = Raphael("canvas", 600, 400);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

//make an arc at 50,50 with a radius of 30 that grows from 0 to 40 of 100 with a bounce
var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 14,
    arc: [200, 200, 0, 100, 60]
});

my_arc.animate({
    arc: [200, 200, amount, 100, 60]
}, 1500, "bounce");

2 个答案:

答案 0 :(得分:0)

使用IE8进行微小的更新 你需要删除路径数组末尾的额外逗号,否则IE8会给出JS错误。

var arcseg = function (cx, cy, radius, start_r, finish_r) {
  start_r = Raphael.rad(start_r);
  finish_r = Raphael.rad(finish_r);

  var start_x = cx + Math.cos( start_r ) * radius,
  start_y = cy + Math.sin( start_r ) * radius,
  finish_x = cx + Math.cos( finish_r ) * radius,
  finish_y = cy + Math.sin( finish_r ) * radius,
  path;

  path = [
    [ "M", start_x, start_y ],
    [ "A", radius, radius, finish_r - start_r,
      (finish_r - start_r > Raphael.rad( 180 )) ? 1 : 0, 
      (finish_r > start_r) ? 1 : 0,        
      finish_x, finish_y ]              
  ];
  return { path: path };
};

答案 1 :(得分:0)

我终于找到了它:D刚刚添加了my_arc.rotate(215,100,100)

<script >

var amount = ("50");


var archtype = Raphael("canvas", 300, 200);
archtype.customAttributes.arc = function (xloc, yloc, value, total, R) {
    var alpha = 360 / total * value,
        a = (90 - alpha) * Math.PI / 180,
        x = xloc + R * Math.cos(a),
        y = yloc - R * Math.sin(a),
        path;
    if (total == value) {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, 1, 1, xloc - 0.01, yloc - R]
        ];
    } else {
        path = [
            ["M", xloc, yloc - R],
            ["A", R, R, 0, +(alpha > 180), 1, x, y]
        ];
    }
    return {
        path: path
    };
};

//make an arc at 50,50 with a radius of 30 that grows from 0 to 40 of 100 with a bounce
var my_arc = archtype.path().attr({
    "stroke": "#f00",
    "stroke-width": 14,
    arc: [100, 100, 0, 100, 60]
});

my_arc.rotate(215, 100 ,100).animate({
    arc: [100, 100, 80, 100, 60]
}, 2000, "bounce");