【问题标题】:Draw multiple circles using paperJS使用 paperJS 绘制多个圆圈
【发布时间】:2013-05-31 19:40:15
【问题描述】:

如何使用 paperjs 绘制多个圆圈?我尝试删除path.removeOnDrag(),它可以工作,删除fillcolor后,输出不符合预期。

<script type="text/paperscript" canvas="canvas">
        function onMouseDrag(event) {
            // The radius is the distance between the position
            // where the user clicked and the current position
            // of the mouse.
            var path = new Path.Circle({
                center: event.downPoint,
                radius: (event.downPoint - event.point).length,
                fillColor: null,
                strokeColor: 'black',
                strokeWidth: 10
            });

            // Remove this path on the next drag event:
            path.removeOnDrag();
        };
</script>

【问题讨论】:

  • 如果您描述您的期望,它会有所帮助。代码完全按照它应该做的那样做,那么您认为问题是什么?此外,一个 jsfiddle.net 示例可能会有所帮助;在这种情况下,jsfiddle.net/vupt3
  • http://jsfiddle.net/vupt3/ 显示正在获得输出。如何在不隐藏第一个圆圈的情况下绘制另一个圆圈。

标签: javascript paperjs


【解决方案1】:

这里有一个简单的解决方案: http://jsfiddle.net/vupt3/1/

因此,在 mouseUp 上,您只需将当前绘制的路径存储到数组中。然后,如果您需要,您可以稍后访问和操作这些环。

// path we are currently drawing
var path = null;

// array to store paths (so paper.js would still draw them)
var circles = [];
function onMouseDrag(event) {
    // The radius is the distance between the position
    // where the user clicked and the current position
    // of the mouse.
    path = new Path.Circle({
        center: event.downPoint,
        radius: (event.downPoint - event.point).length,
        fillColor: null,
        strokeColor: 'black',
        strokeWidth: 10
    });

    // Remove this path on the next drag event:
    path.removeOnDrag();

};

function onMouseUp(event) {
    // if mouseUp event fires, save current path into the array
    circles.push(path);
};

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多