使用paperJS绘制多个圆圈(Draw multiple circles using paperJS)

编程入门 行业动态 更新时间:2024-10-28 11:31:45
使用paperJS绘制多个圆圈(Draw multiple circles using 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>

How can I draw multiple circles using paperjs? I tried removing path.removeOnDrag() it works and after removing fillcolor, but the output is not as expected.

<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); };

Here an easy solution: http://jsfiddle.net/vupt3/1/

So on mouseUp you just store the currently drawn path into the array. Then also if you need to, you can access and manipulate those rings later on.

// 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); };

更多推荐

本文发布于:2023-08-02 14:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1376884.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   圆圈   paperJS   circles   multiple

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!