前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ec函数,转的

ec函数,转的

作者头像
用户3519280
发布2023-07-08 14:55:44
1330
发布2023-07-08 14:55:44
举报
文章被收录于专栏:c++ 学习分享c++ 学习分享

1

代码语言:javascript
复制
/**
 * @author Mr_老冷 QQ:1920712147
 * @description 判断数据类型
 * @param arg{any}
 * @return {string|null|undefined}
 */
function typeOf(arg) {
    if (arg === null) return null
    if (arg === undefined) return undefined
    return arg.constructor.name
}
let data = device.tcDeviceId()
logd(typeof data)
//object
logd(typeOf(data));
//String

2

代码语言:javascript
复制
/**
 * @author Mr_老冷 QQ1920712147
 * @description 判断数组是否不为空
 * @param arr {Array}  数组
 * @return {boolean}
 */
function isNotEmptyArray(arr) {
    if (!arr) return false
    return arr.length !== 0;
}

例子

代码语言:javascript
复制
let res = getLastNotification("com.x", 100)
if (isNotEmptyArray(res)) {
    for (let i = 0; i < res.length; i++) {
        logd(res[i]);
    }
}

3

代码语言:javascript
复制
/**
 * @author Mr_老冷 QQ1920712147
 * @constructor
 */
function SwipeRnd() {
    this.step = 0.08
}
 
/**
 * @author Mr_老冷 QQ1920712147
 * @type {SwipeRnd}
 */
const rSwipe = new SwipeRnd()
 
 
/**
 * @author Mr_老冷 QQ1920712147
 * @description 仿真滑动
 * @param startX {number} 起点x
 * @param startY {number} 起点y
 * @param endX {number} 终点x
 * @param endY {number} 终点y
 * @param timeStart {number} 随机延迟1,默认50ms
 * @param timeEnd {number} 随机延迟2,默认timeStart+50ms
 * @param timeOut {number} 超时,默认2s
 * @param step {number} 步进,默认0.08
 * @return {boolean}
 */
SwipeRnd.prototype.rndSwipe = function (startX, startY, endX, endY,
                                        timeStart, timeEnd, timeOut, step) {
    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)
}
/**
 * @author Mr_老冷 QQ1920712147
 * @description 二指仿真滑动
 * @param startX {number} 起点x
 * @param startY {number} 起点y
 * @param endX {number} 终点x
 * @param endY {number} 终点y
 * @param timeStart {number} 随机延迟1,默认50ms
 * @param timeEnd {number} 随机延迟2,默认timeStart+50ms
 * @param timeOut {number} 超时,默认2s
 * @param step {number} 步进,默认0.08
 * @return {boolean}
 */
SwipeRnd.prototype.rndSwipeTwo = function (startX, startY,
                                           endX, endY,
                                           timeStart, timeEnd, timeOut, step) {
    timeStart = timeStart || 50
    timeEnd = timeEnd || timeStart + 50
    timeOut = timeOut || 2 * 1000
    this.step = step || this.step
    return this._gestureTwo(this._rndSwipe(startX, startY, endX, endY), this._rndSwipe(startX, startY, endX, endY),
        random(timeStart, timeEnd), timeOut)
}
 
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._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) {
        xxyy = [~~(this._bezier_curves(point, i).x), ~~(this._bezier_curves(point, i).y)]
        xxy.push(xxyy);
    }
    return xxy
}
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._gestureTwo = function (swipeList, time, time1) {
    let swipe = swipeList[0],
        swipe1 = swipeList[1],
        touch1 = [{"action": 0, "x": swipe[0][0], "y": swipe[0][1], "pointer": 1, "delay": time}],
        touch2 = [{"action": 0, "x": swipe1[0][0], "y": swipe1[0][1], "pointer": 2, "delay": time}]
 
    for (let i = 1; i < swipe.length - 1; i++) {
        touch1.push({"action": 2, "x": swipe[i][0], "y": swipe[i][1], "pointer": 1, "delay": time});
        touch2.push({"action": 2, "x": swipe1[i][0], "y": swipe1[i][1], "pointer": 2, "delay": time});
    }
    touch1.push({
        "action": 1,
        "x": swipe[swipe.length - 1][0],
        "y": swipe[swipe.length - 1][1],
        "pointer": 1,
        "delay": time
    })
    touch2.push({
        "action": 1,
        "x": swipe1[swipe1.length - 1][0],
        "y": swipe1[swipe1.length - 1][1],
        "pointer": 2,
        "delay": time
    })
    return multiTouch(touch1, touch2, null, time1);
}

例子

代码语言:javascript
复制
//单指滑动
//默认方法
rSwipe.rndSwipe(200, 700, 200, 200)
//调整步进,默认0.08
rSwipe.step = 0.05
rSwipe.rndSwipe(200, 700, 200, 200)
//调整调整随机时间,默认50-100
rSwipe.rndSwipe(200, 700, 200, 200, 50, 80)
//调整超时时间
rSwipe.rndSwipe(200, 700, 200, 200, 50, 80, 1000)
 
//双指滑动,用法同上

4

代码语言:javascript
复制
/**
 * @author Mr_老冷 QQ:1920712147
 * @date 20210722
 */
Array.prototype.unique = function () {
    let tmpS = new Set(this), i = 0
    for (let tmp of tmpS) {
        this[i] = tmp
        i++
    }
    this.length = i
}
代码语言:javascript
复制
let a = [1, 2, 2, 3, 4]
a.unique()
console.log(a)
//[1,2,3,4]
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2021-08-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档