javascript - 使用 paperJS 绘制多个圆圈

标签 javascript paperjs

如何使用 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>

最佳答案

这里有一个简单的解决方案: 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);
};

关于javascript - 使用 paperJS 绘制多个圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16864688/

相关文章:

javascript - 在 PaperJS 中调整屏幕大小和移动设备旋转后禁用重绘 Canvas

javascript - 通过 Panzoom 变换放大时获取 Canvas 点击坐标

javascript - 在 javaScript 动态添加一些标签到我的 HTML 之后我的设计改变了,我该如何解决这个问题

javascript - Paperjs metaballs 不工作/显示

iphone - HTML 音频播放导致 iPhone 闪烁

javascript - 为什么我不能将 Symbol 定义为构造函数?

javascript - 在文本/模板中编辑 HTML

javascript - Firefox 中具有可调整大小列的 JQuery UI 表性能问题

javascript - 英特尔应用程序框架所有面板在启动时加载

javascript - Paper.js 段未定义