gpt4 book ai didi

raphael - 在 raphael js 中绘制中心弧

转载 作者:行者123 更新时间:2023-12-03 10:31:21 25 4
gpt4 key购买 nike

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

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

最佳答案

这个答案是可以的,但不能动画化。我从极地时钟中为你撕下了重要的东西。这是一个红色的弧线,可以动画生长。请享用。

// 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 - 在 raphael js 中绘制中心弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5061318/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com