如何在纸上为动态创建的圆分配半径值.js

How to assign the radius value for the dynamically created circle in paper.js

本文关键字:分配 js 创建 动态      更新时间:2023-09-26

我想像在绘画中画一个圆,如果鼠标向下意味着它占据了点,如果拖动鼠标意味着圆的半径应该相应地增加,谁能帮我

您可以计算鼠标下点与当前鼠标位置之间的距离

然后将该距离用作圆的半径

下面是一些可以做到这一点的代码:

function onMouseDrag(event) {
    var trackingCircle = new Path.Circle({
        position: event.downPoint, 
        radius: event.downPoint.subtract(event.point).length,
        dashArray: [2, 2],
        strokeColor: 'red'
    })
    trackingCircle.removeOn({
        drag: true,
        down: true,
        up:true
    })
}
function onMouseUp(event) {
    var circle = new Path.Circle({
        position: event.downPoint, 
        radius: event.downPoint.subtract(event.point).length,
        strokeColor: 'black'
    })
}

这是实际的草图,(在画布上单击并拖动(。