Auto.js 画布canvas

"ui";
importClass(android.graphics.Color);
ui.layout(
    <vertical>
        <canvas id="board" w="*" h="*"/>
    </vertical>
);
var paint = new Paint();
paint.setStrokeWidth(2);
paint.setColor(Color.parseColor("#ffffff"));
ui.board.on("draw", function(canvas) {
    canvas.drawColor(0,android.graphics.PorterDuff.Mode.CLEAR);
    canvas.drawLine(0,0,random(0,1080),random(0,2340), paint);
});

画三角形 五角星
在这里插入图片描述

"ui";
Math.toRadians=function(a) {
    //自定义android 抛物线
    let PI = 3.14159265358979323846;
    return a / 180 * PI;
}
importClass(android.graphics.Path);
importClass(android.graphics.Color);
ui.layout(
    <vertical>
        <canvas id="board" w="*" h="*"/>
    </vertical>
);
fivePoints(500, 800, 100)
var paint = new Paint();
paint.setStrokeWidth(2);
paint.setColor(Color.parseColor("#ffffff"));
ui.board.on("draw", function(canvas) {
    canvas.drawColor(0, android.graphics.PorterDuff.Mode.CLEAR);
    //canvas.drawLine(0,0,random(0,1080),random(0,2340), paint);
    画三角形(canvas, 500, 500)
    画五角星(canvas, 0, 0)

});

function 画三角形(canvas, x, y) {
    path = new Path(); //绘制多边形的类
    path.moveTo(x, y); //尖
    path.lineTo(x - 100, y + 100); //右下角
    path.lineTo(x + 100, y + 100); //左下角
    path.close(); //闭合图形
    canvas.drawPath(path, paint); //三角形
}

function 画五角星(canvas, x, y) {
    let xA = 400;
    let yA = 200;
    let r = 100; //五角星边长
    let path = new Path();
    let floats = fivePoints(xA, yA, r);
    for (let i = 0; i < floats.length - 1; i++) {
        path.lineTo(floats[i], floats[i += 1]);
    }
    canvas.drawPath(path, paint); //三角形
}

function fivePoints(xA, yA, rFive) {
    /**
     * @param xA 起始点位置A的x轴绝对位置
     * @param yA 起始点位置A的y轴绝对位置
     * @param rFive 五角星边的边长
     */
    let xB = 0;
    let xC = 0;
    let xD = 0;
    let xE = 0;
    let yB = 0;
    let yC = 0;
    let yD = 0;
    let yE = 0;
    xD = (xA - rFive * Math.sin(Math.toRadians(18)));
    xC = (xA + rFive * Math.sin(Math.toRadians(18)));
    yD = yC = (yA + Math.cos(Math.toRadians(18)) * rFive);
    yB = yE = (yA + Math.sqrt(Math.pow((xC - xD), 2) - Math.pow((rFive / 2), 2)));
    xB = xA + (rFive / 2);
    xE = xA - (rFive / 2);
    lets = [
        xA,
        yA,
        xD,
        yD,
        xB,
        yB,
        xE,
        yE,
        xC,
        yC,
        xA,
        yA
    ];
    log(lets)
    return lets;
}

画小水滴
在这里插入图片描述

function 画小水滴(canvas){
    let x=800
    let y=1000
    let 半径=30
    path = new Path(); //绘制多边形的类
    path.moveTo(x, y-半径*2); //尖
    path.lineTo(x - 半径, y); //右下角
    path.lineTo(x + 半径, y); //左下角
    path.close(); //闭合图形
    canvas.drawPath(path, paint); //三角形
    canvas.drawCircle(x,y,半径 , paint);
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值