Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用Paper.js设置圆上多边形点的动画_Javascript_Animation_Paperjs - Fatal编程技术网

Javascript 使用Paper.js设置圆上多边形点的动画

Javascript 使用Paper.js设置圆上多边形点的动画,javascript,animation,paperjs,Javascript,Animation,Paperjs,我需要为多边形的一个点(称为分段)设置动画,在原点位于原始多边形点的圆上旋转它。见下图: 我正在尝试使用以下代码: // Draw the polygon var polygon = new Path.RegularPolygon({ center: [100, 100], sides: 8, radius: 80, }); // Animate view.onFrame = function (event) { var offset = new Point(M

我需要为多边形的一个点(称为分段)设置动画,在原点位于原始多边形点的圆上旋转它。见下图:

我正在尝试使用以下代码:

// Draw the polygon
var polygon = new Path.RegularPolygon({
    center: [100, 100],
    sides: 8,
    radius: 80,
});
// Animate
view.onFrame = function (event) {
    var offset = new Point(Math.cos(event.time*2), Math.sin(event.time*2));
    polygon.firstSegment.point = polygon.firstSegment.point.add(offset);
};
但我有两个问题:

  • 圆的原点是错误的
  • 经过一段时间的动画,它开始以一些奇怪的(显然是)随机的方式旋转。它似乎改变了圆的原点
下面是查看其运行的全部代码:


有人能帮忙吗?多亏了

问题在于,在每一帧,您都参考了在上一帧中移动了一点的第一段的位置,因此偏移量相加

相反,只需在起点记录中心并从该点偏移:

var center = polygon.firstSegment.point.clone();
[...]
polygon.firstSegment.point = center.add(offset);