js中绘制居中圆弧

js中绘制居中圆弧

本文介绍了在Raphael js中绘制居中圆弧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用raphael.js绘制各种大小的同心圆弧.我试图理解 http://raphaeljs.com/polar-clock.html后面的代码,它与我想要的非常相似,但是,即使没有评论,也很难理解.

I need to draw concentric arcs of various sizes using raphael.js. I tried to understand the code behind http://raphaeljs.com/polar-clock.html, which is very similar to what I want, but, whithout comments, it is quite difficult to fathom.

理想情况下,我需要一个函数来创建一条距某个中心点给定距离,以某个角度开始并以另一个角度结束的路径.

Ideally, I would need a function that creates a path that is at a given distance from some center point, starts at some angle and ends at some other angle.

推荐答案

该答案是可以的,但不能设置动画.我为您从极地时钟中删除了重要内容.这是一个动画的红色弧线.享受.

That answer is ok, but cant be animated. I ripped the important stuff out of polar-clock for you. Here is a red arc that animates growing. enjoy.

// Custom Arc Attribute, position x&y, value portion of total, total value, Radius
var archtype = Raphael("canvas", 200, 100);
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: [50, 50, 0, 100, 30]
});

my_arc.animate({
    arc: [50, 50, 40, 100, 30]
}, 1500, "bounce");

这篇关于在Raphael js中绘制居中圆弧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 23:23
查看更多