2015-11-19 32 views
0

与路径开始 - 或者很多的这些...是否可以获取/设置现有路径的半径?圆形?

var c=paper.Path.Circle(centerPoint, 30); 
c.strokeColor=""; 

我想有一圈呈线性增长的半径。我可以这样做:

var children = paper.project.activeLayer.children; 
paper.view.onFrame = function(event) { 
    for (var i = 0; i < children.length; i++) { 
     var item = children[i]; 
     item.scale(1.01); 
    } 

但是,指数增加半径!

我可以得到圆的半径并改变它吗?或者我必须创建一个新的,删除旧的?
scale()这样做?

我也想删除一个给定大小的圆圈。

感谢, 塞巴斯蒂安

+0

如果我的回答解决你的问题,我将不胜感激你接受的答案通过给它一个绿色的复选标记。 – bmacnaughton

回答

1

你可以得到一个圆的半径,虽然这是间接的。

var radius = circle.bounds.topCenter.y - circle.bounds.center.y;

var radius = circle.bounds.width/2

给你一个圆的半径。但是一个圆圈存储为带有句柄的4段线段,而不是圆形对象,因此半径不会存储在任何位置。

为了使它看起来增长,你将不得不删除旧的并绘制一个新的较大的尺寸。

也可以对其进行缩放,但是您希望对其进行缩放而不会混合缩放。所以如果你想要它增长1.01,然后1.02而不是1.0201等,你将需要每次调整缩放因子。

这不是完全清楚你想怎么长大了一圈,但这里的一些代码,让你想要做什么一些假设:

function Scale() { 
    this.original = 1.0; 
    this.current = 1.0; 
} 

// target refers to original size in fractional terms, e.g., to 
// grow by 1% specify 1.01 or to shrink by 1% specify 0.99. It returns 
// the scale factor to apply to the current scale to achieve the 
// target. So to increase the scale by 10% of the original size each 
// time: 
// 
//  var s = new Scale(); 
// 
//  for (i = 1.1; i <= 2.05; i += 0.1) { 
//   var scaleFactor = s.scale(i); 
//  } 
// 
// note the i <= 2.05 to allow for real number math issues. 
// 
Scale.prototype.scale = function(target) { 
    // get the scaling factor from the original size 
    var oFactor = target/this.original; 
    // now get the factor to scale the current size by 
    var cFactor = oFactor/this.current; 
    this.current = oFactor; 
    return cFactor; 
} 
+0

我最终将半径作为属性添加到圆形路径 - 最终甚至使用'.data'属性作为自定义数据的容器对象...然后我可以调用'item.scale((item.data.r + 10)/item.data.r)'。 – sebhaase