使用贝叶斯曲线滑动安卓屏幕(autojsPro7)

简介: 使用贝叶斯曲线滑动安卓屏幕(autojsPro7)

一、运行环境

1.1 Vscode Version: 1.78.2 (user setup)

1.2 Autojs 7.0.4-1

1.3 安卓模拟 雷电7

1.4 筷子 v9.2.21.18848

二、实际代码

概率Js,随机后进行概率分配直线还是曲线

/**
 * 概率0-9 大于3的时候采用曲线概率 小于3的时候直线概率
 */
function randomFunction(){
    return Math.floor(Math.random() * 10);  
}

滑动屏幕函数

/**
 * 曲线滑动屏幕向下滑动并延迟n秒
 */
function swipeCurveDown(qx, qy, zx, zy, time,timesInterval){
    toastLog("曲线滑动");
    var xxy = [time];
    var point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    };
    var dx1 = {
        "x": random(qx - 100, qx + 100),
        "y": random(qy, qy + 50)
    };
    var dx2 = {
        "x": random(zx - 100, zx + 100),
        "y": random(zy, zy + 50),
    };
    var dx3 = {
        "x": zx,
        "y": zy
    };
    for (var i = 0; i < 4; i++) {
        eval("point.push(dx" + i + ")");
    };
    for (let i = 0; i < 1; i += 0.08) {
        let newPoint=bezier_curves(point, i);
        xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)]
        xxy.push(xxyy);
    }
    gesture.apply(null, xxy);
    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 2) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 直线滑动屏幕向下滑动并延迟n秒
 */
function swipeLineDown(startX, startY, endX, endY, pressTime, timesInterval) {
    toastLog("直线滑动");
    swipe(startX, startY, endX, endY, pressTime);
    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 3) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 贝塞尔曲线
 * @param {坐标点} ScreenPoint 
 * @param {偏移量} Offset 
 */
function bezier_curves(ScreenPoint, Offset) {
    cx = 3.0 * (ScreenPoint[1].x - ScreenPoint[0].x);
    bx = 3.0 * (ScreenPoint[2].x - ScreenPoint[1].x) - cx;
    ax = ScreenPoint[3].x - ScreenPoint[0].x - cx - bx;
    cy = 3.0 * (ScreenPoint[1].y - ScreenPoint[0].y);
    by = 3.0 * (ScreenPoint[2].y - ScreenPoint[1].y) - cy;
    ay = ScreenPoint[3].y - ScreenPoint[0].y - cy - by;
    tSquared =Offset * Offset;
    tCubed = tSquared * Offset;
    result = {
        "x": 0,
        "y": 0
    };
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * Offset) + ScreenPoint[0].x;
    result.y = (ay * tCubed) + (by * tSquared) + (cy * Offset) + ScreenPoint[0].y;
    return result;
}

三、真象(运行日志)

16:17:03.637/I: 剩余4秒...

16:17:04.640/I: 剩余3秒...

16:17:05.640/I: 剩余2秒...

16:17:06.641/I: 剩余1秒...

16:17:10.320/D: 直线滑动

16:17:31.690/D: 曲线滑动

16:17:53.247/D: 直线滑动

16:18:15.925/D: 直线滑动

16:18:37.583/D: 直线滑动

16:18:58.384/D: 曲线滑动

16:19:19.248/D: 直线滑动

16:19:42.211/D: 直线滑动

16:20:03.051/D: 曲线滑动

16:20:25.343/D: 直线滑动

16:20:47.903/D: 直线滑动

16:21:09.548/D: 曲线滑动

16:21:31.922/D: 曲线滑动

四、完整代码(执行筷子的代码)

auto.waitFor();//判断和等待开启无障碍
console.show(); //开启日志(悬浮窗权限)
app.launchApp('快手');//只有一个快手以直接Launch就可以,不用包名
cutDownBySleep(8);//等待splash时间倒计时
timesInterval=20
let x1 = random(device.width * 0.8, device.width * 0.9);
let y1 = device.height - (device.height * 0.15)
let x2 = random(device.width * 0.8, device.width * 0.9);
let y2 = device.height * 0.2
let pressTime = random(700, 800);
adolescentWindows()
closeUpgrageTip()
clickVideo()
while(true){
    swipeScreenDown(x1, y1, x2, y2,pressTime, timesInterval) 
}
function clickVideo() {
    if (text("精选").exists()) {
        clickControlBounds(text("精选"))
    }
}
/**
 * 青少年窗口
 */
function adolescentWindows() {
    if (text("我知道了").exists()) {
        text("我知道了").findOnce().click();
    }
    if (text("知道了").exists()) {
        text("知道了").findOnce().click();
    }
}
/**
 * 直接无视
 */
function closeUpgrageTip() {
    if (text("直接无视").exists()) {
        text("直接无视").findOnce().click();
    }
    if (text("刷新重试").exists()) {
        text("刷新重试").findOnce().click();
    }
}
/**
 * 点击屏幕上的坐标
 * @param {坐标} b 
 */
function clickControlBounds(element) {
    let clickResult = false;
    if (element == null) {
        return false;
    }
    try {
        if (element.exists()) {
            let b = element.findOnce().bounds();
            clickResult = click(b.centerX(), b.centerY());
            sleep(random(2000, 3200));
        } else {
        }
        return clickResult;
    } catch (error) {
        toastLog("clickControlBounds方法出现错误:" + error)
        return false;
    }
}
/**
 * 倒计时方法适用于脚本
 * @param {倒计时时间} lasterTime 
 */
function cutDownBySleep(lasterTime,message) {
    message=message || ""
    for (let i = lasterTime; i => 0; i--) {
        console.info(message+"剩余" + i + "秒...")
        sleep(1000)
        if (i == 1) {
            return
        }
    }
}
/**
 * 概率0-9 大于3的时候采用曲线概率 小于3的时候直线概率
 */
function randomFunction(){
    return Math.floor(Math.random() * 10);  
}
/**
 * 滑动(默认概率是百分之三十)
 * @param {*} qx 
 * @param {*} qy 
 * @param {*} zx 
 * @param {*} zy 
 * @param {*} time 
 * @param {*} timesInterval 
 */
function swipeScreenDown(qx, qy, zx, zy, time, timesInterval) {
    let probability=randomFunction()
    if (probability>=7) {
        swipeCurveDown(qx, qy, zx, zy, time, timesInterval); //曲线概率
    } else {
        swipeLineDown(qx, qy, zx, zy, time, timesInterval); //直线概率
    }
}
/**
 * 曲线滑动屏幕向下滑动并延迟n秒
 */
function swipeCurveDown(qx, qy, zx, zy, time,timesInterval){
    toastLog("曲线滑动");
    var xxy = [time];
    var point = [];
    var dx0 = {
        "x": qx,
        "y": qy
    };
    var dx1 = {
        "x": random(qx - 100, qx + 100),
        "y": random(qy, qy + 50)
    };
    var dx2 = {
        "x": random(zx - 100, zx + 100),
        "y": random(zy, zy + 50),
    };
    var dx3 = {
        "x": zx,
        "y": zy
    };
    for (var i = 0; i < 4; i++) {
        eval("point.push(dx" + i + ")");
    };
    for (let i = 0; i < 1; i += 0.08) {
        let newPoint=bezier_curves(point, i);
        xxyy = [parseInt(newPoint.x), parseInt(newPoint.y)]
        xxy.push(xxyy);
    }
    gesture.apply(null, xxy);
    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 2) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 直线滑动屏幕向下滑动并延迟n秒
 */
function swipeLineDown(startX, startY, endX, endY, pressTime, timesInterval) {
    toastLog("直线滑动");
    swipe(startX, startY, endX, endY, pressTime);
    let randomMin = timesInterval * 1000;
    let randomMax = (parseInt(timesInterval) + 3) * 1000;
    let delayTime = random(randomMin, randomMax);
    sleep(delayTime);
}
/**
 * 贝塞尔曲线
 * @param {坐标点} ScreenPoint 
 * @param {偏移量} Offset 
 */
function bezier_curves(ScreenPoint, Offset) {
    cx = 3.0 * (ScreenPoint[1].x - ScreenPoint[0].x);
    bx = 3.0 * (ScreenPoint[2].x - ScreenPoint[1].x) - cx;
    ax = ScreenPoint[3].x - ScreenPoint[0].x - cx - bx;
    cy = 3.0 * (ScreenPoint[1].y - ScreenPoint[0].y);
    by = 3.0 * (ScreenPoint[2].y - ScreenPoint[1].y) - cy;
    ay = ScreenPoint[3].y - ScreenPoint[0].y - cy - by;
    tSquared =Offset * Offset;
    tCubed = tSquared * Offset;
    result = {
        "x": 0,
        "y": 0
    };
    result.x = (ax * tCubed) + (bx * tSquared) + (cx * Offset) + ScreenPoint[0].x;
    result.y = (ay * tCubed) + (by * tSquared) + (cy * Offset) + ScreenPoint[0].y;
    return result;
}
目录
相关文章
|
6月前
|
开发工具 Android开发
rk平台Android12屏幕永不休眠
rk平台Android12屏幕永不休眠
109 1
|
2月前
|
编解码 开发工具 Android开发
Android平台实现屏幕录制(屏幕投影)|音频播放采集|麦克风采集并推送RTMP或轻量级RTSP服务
Android平台屏幕采集、音频播放声音采集、麦克风采集编码打包推送到RTMP和轻量级RTSP服务的相关技术实现,做成高稳定低延迟的同屏系统,还需要有配套好的RTMP、RTSP直播播放器
|
3月前
|
Android开发
Android使用ViewPager做无限轮播,人为滑动时停止
Android使用ViewPager做无限轮播,人为滑动时停止
75 2
|
4月前
|
Android开发
Android仿高德首页三段式滑动
Android仿高德首页三段式滑动
134 0
|
5月前
|
编解码 Android开发
Android 解决TextView多行滑动与NestedScrollView嵌套滑动冲突的问题
Android 解决TextView多行滑动与NestedScrollView嵌套滑动冲突的问题
89 0
|
6月前
|
Shell Android开发
ADB更改Android设备屏幕显示方向
ADB更改Android设备屏幕显示方向
347 5
|
5月前
|
XML Android开发 UED
|
6月前
|
Android开发
获取Android设备屏幕大小
获取Android设备屏幕大小
123 3
|
6月前
|
Android开发
Android使用ViewPager实现图片轮播系列之三:手动滑动 + 左右箭头(1)
Android使用ViewPager实现图片轮播系列之三:手动滑动 + 左右箭头(1)
|
6月前
|
XML Java Android开发
Android系统 添加动态控制屏幕方向、强制APP横竖屏方向
Android系统 添加动态控制屏幕方向、强制APP横竖屏方向
754 1