我是rapheal js& amp;的新手我只需要使用paper.path()对象创建一个动态椭圆。
虽然我们可以使用paper.ellipse()来完成它,但是我需要它只能按照预先存在的代码的路径方式来完成。我用Google搜索并获得了circle2path()的解决方案。
让我举一个例子来描述。
var paper = Raphael(10,10, 250, 250);
var start_x = 170;//this has to be dynamic
var start_y = 160;// so these are also
var r_x = 40;
var r_y = 35;
var ellipse = paper.ellipse(start_x,start_y,r_x,r_y);
// here instead of paper.ellipse, I need to use paper.path()
//for example I used path to create circle
var radius = 50;
var circle_path = "M"+ (start_x)+ (start_y-radius)+"A"+ radius+radius+0+1+1+(start_x-0.1)+(start_y-radius)+ "z";
var circle = paper.path(circle_path);
它适用于圆圈。有没有办法处理椭圆。
提前致谢。
答案 0 :(得分:1)
尤里卡.........
我从this question获得了解决方案。
var paper = Raphael(10,10, 250, 250);
var start_x = 170;//this has to be dynamic
var start_y = 160;// so these are also
var r_x = 40;
var r_y = 35;
var ellipse = [["M", (start_x - r_x), (start_y)], ["a", r_x, r_y ,0, 1,1, 0,0.1 ],"z"];
var draw = paper.path(ellipse);
就是这样,我想要的。所以我们可以为它创建一个函数。
var ellipse2path = function(start_x,start_y,r_x,r_y){
return [["M", (start_x - r_x), (start_y)], ["a", r_x, r_y ,0, 1,1, 0,0.1 ],"z"];
};