easyclick模拟手指运动

单指:

直线滑动:

swipeToPoint(x,y ex,ey, swipeTime)

模拟手指微微曲线滑动:

function SwipeRnd() {
    this.step = 0.08
}
SwipeRnd.prototype._bezier_curves = function (cp, t) {
    let cx = 3.0 * (cp[1].x - cp[0].x),
        bx = 3.0 * (cp[2].x - cp[1].x) - cx,
        ax = cp[3].x - cp[0].x - cx - bx,
        cy = 3.0 * (cp[1].y - cp[0].y),
        by = 3.0 * (cp[2].y - cp[1].y) - cy,
        ay = cp[3].y - cp[0].y - cy - by,
        tSquared = t * t,
        tCubed = tSquared * t
    return {
        "x": (ax * tCubed) + (bx * tSquared) + (cx * t) + cp[0].x,
        "y": (ay * tCubed) + (by * tSquared) + (cy * t) + cp[0].y
    }
}
SwipeRnd.prototype._gesture = function (swipeList, time, time1) {
    let touch1 = [{"action": 0, "x": swipeList[0][0], "y": swipeList[0][1], "pointer": 1, "delay": time}]
    for (let i = 1; i < swipeList.length - 1; i++) {
        touch1.push({"action": 2, "x": swipeList[i][0], "y": swipeList[i][1], "pointer": 1, "delay": time});
    }
    touch1.push({
        "action": 1,
        "x": swipeList[swipeList.length - 1][0],
        "y": swipeList[swipeList.length - 1][1],
        "pointer": 1,
        "delay": time
    })
    // 实现手指移动
    return multiTouch(touch1, null, null, time1);
}
SwipeRnd.prototype._rndSwipe = function (qx, qy, zx, zy) {
    let xxyy = [],
        xxy = [],
        point = [],
        dx = [{
            "x": random(qx, qx + 50),
            "y": random(qy, qy + 50)
        }, {
            "x": random(qx - 100, qx + 100),
            "y": random(qy, qy + 50)
        }, {
            "x": random(zx - 100, zx + 100),
            "y": random(zy, zy + 50),
        }, {
            "x": zx,
            "y": zy
        }]
    for (let i = 0; i < dx.length; i++) {
        point.push(dx[i])
    }
    for (let i = 0; i < 1; i += this.step) {
        // _bezier_curves曲线
        xxyy = [~~(this._bezier_curves(point, i).x), ~~(this._bezier_curves(point, i).y)]
        xxy.push(xxyy);
    }
    return xxy
}
SwipeRnd.prototype.rndSwipe = function (startX, startY, endX, endY,
                                        timeStart, timeEnd, timeOut, step) {
    // 默认50开始,100结束,超时2000,step0.08
    timeStart = timeStart || 50
    timeEnd = timeEnd || timeStart + 50
    timeOut = timeOut || 2 * 1000
    this.step = step || this.step
    return this._gesture(this._rndSwipe(startX, startY, endX, endY), random(timeStart, timeEnd), timeOut)
}

使用:

const rSwipe = new SwipeRnd()
rSwipe.step = 0.05
rSwipe.rndSwipe(x,y,ex,ey)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值