HarmonyOS应用开发-三方组件太极图案例
头像 Q 2022-02-27 17:13:20    发布
1448 浏览 16 点赞 24 收藏

HarmonyOS应用开发-三方组件太极图案例-鸿蒙开发者社区
主代码页,示例代码:


<div class="container">
    <div class="canvas-container">
        <canvas ref="ref_canvas" class="canvas" id="canvasId"/>
    </div>

</div>

/*index.css*/
.container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
/*    background-color: #5e7c85;*/
}

.canvas-container {
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    width: 100%;
}

.canvas {
    width: 340px;
    height: 340px;
    justify-content: center;
    align-items: center;
    align-content: center;
    margin-left: 10px;
    margin-right: 10px;
}

@keyframes rotateAnim {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

#canvasId {
    animation: rotateAnim 5s 0s linear infinite;
}

/*index.js*/
export default {
    data: {},
    onShow() {
        this.draw(170, 170);
    },
    draw(x, y) {
        const el = this.$refs.ref_canvas;
        var ctx = el.getContext('2d', {
            antialias: true
        });

        //半径
        let radius = 150;
        ctx.beginPath();
        ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
        ctx.stroke();
        ctx.fillStyle = 'black';
        ctx.beginPath();
        ctx.moveTo(x, y - radius);
        ctx.bezierCurveTo(x - radius, y - radius / 2, x + radius, y + radius / 2, x, y + radius);
        ctx.arc(x, y, radius, -(Math.PI / 180) * 270, (Math.PI / 180) * 270, true);
        ctx.closePath();
        ctx.fill();
        ctx.beginPath();
        ctx.arc(x, y + radius / 2, 20, 0, 2 * Math.PI, false);
        ctx.fill();
        ctx.fillStyle = 'white';
        ctx.beginPath();
        ctx.arc(x, y + -radius / 2, 20, 0, 2 * Math.PI, false);
        ctx.fill();
    }
}

案例效果:

HarmonyOS应用开发-三方组件太极图案例-鸿蒙开发者社区


©本站发布的所有内容,包括但不限于文字、图片、音频、视频、图表、标志、标识、广告、商标、商号、域名、软件、程序等,除特别标明外,均来源于网络或用户投稿,版权归原作者或原出处所有。我们致力于保护原作者版权,若涉及版权问题,请及时联系我们进行处理。
分类
其它
头像

Q

我还没有写个人简介......

85

帖子

0

提问

245

粉丝

关注
最新发布
热门推荐
地址:北京市朝阳区北三环东路三元桥曙光西里甲1号第三置业A座1508室 商务内容合作QQ:2291221 电话:13391790444或(010)62178877
版权所有:电脑商情信息服务集团 北京赢邦策略咨询有限责任公司
声明:本媒体部分图片、文章来源于网络,版权归原作者所有,我司致力于保护作者版权,如有侵权,请与我司联系删除

京ICP备:2022009079号-2

京公网安备:11010502051901号

ICP证:京B2-20230255