首页前端开发HTMLCanvas制作旋转的太极的示例

Canvas制作旋转的太极的示例

时间2024-01-24 22:31:21发布访客分类HTML浏览432
导读:收集整理的这篇文章主要介绍了Canvas制作旋转的太极的示例,觉得挺不错的,现在分享给大家,也给大家做个参考。 前言好久没动canvas了,今下午突然想回顾一下,就写了个旋转的太极,哈哈,蛮好玩的,在这里就将自己写的过程展示出来,...
收集整理的这篇文章主要介绍了Canvas制作旋转的太极的示例,觉得挺不错的,现在分享给大家,也给大家做个参考。

前言

好久没动canvas了,今下午突然想回顾一下,就写了个旋转的太极,哈哈,蛮好玩的,在这里就将自己写的过程展示出来,旋转使用的css实现的,没有用canvas自己的,希望大佬们不要吐槽。

css

body{
        background: #ddd;
}
#canvas{
        posITion: absolute;
        left: 40%;
        top: 30%;
        -webkit-transform: translate(-50%,-50%);
        -moz-transform: translate(-50%,-50%);
        -ms-transform: translate(-50%,-50%);
        -o-transform: translate(-50%,-50%);
        transform: translate(-50%,-50%);
        -webkit-animation: testAniMATE 3s linear infinite;
        -o-animation: testAnimate 3s linear infinite;
        animation: testAnimate 3s linear infinite;
}
@keyframes testAnimate {
    From {
            -webkit-transform: rotate(0);
            -moz-transform: rotate(0);
            -ms-transform: rotate(0);
            -o-transform: rotate(0);
            transform: rotate(0);
    }
    to {
            -webkit-transform: rotate(360deg);
            -moz-transform: rotate(360deg);
            -ms-transform: rotate(360deg);
            -o-transform: rotate(360deg);
            transform: rotate(360deg);
    }
}
    

htML

body>
        canvas id="canvas" width="500" height="500">
    /canvas>
    /body>
    

js

let ctx = document    .getElementById("canvas")    .getContext("2d");
    // left-black-Bigctx.beginPath();
    ctx.fillStyle = "#000";
    ctx.arc(250,250,200,Math.PI/2,Math.PI*1.5,false);
    ctx.closePath();
    ctx.fill();
    // right-white-bigctx.beginPath();
    ctx.fillStyle = "#fff";
    ctx.arc(250,250,200,Math.PI/2,Math.PI*1.5,true);
    ctx.closePath();
    ctx.fill();
    // top-black-middlectx.beginPath();
    ctx.fillStyle = "#000";
    ctx.arc(250,150,100,Math.PI/2,Math.PI*1.5,true);
    ctx.closePath();
    ctx.fill();
    // bottom-white-middlectx.beginPath();
    ctx.fillStyle = "#fff";
    ctx.arc(250,350,100,Math.PI/2,Math.PI*1.5,false);
    ctx.closePath();
    ctx.fill();
    // top-white-smallctx.beginPath();
    ctx.fillStyle = "#fff";
    ctx.arc(250,150,25,0,Math.PI*2);
    ctx.closePath();
    ctx.fill();
    // bottom-black-smallctx.beginPath();
    ctx.fillStyle = "#000";
    ctx.arc(250,350,25,0,Math.PI*2);
    ctx.closePath();
    ctx.fill();
    

效果

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: Canvas制作旋转的太极的示例
本文地址: https://pptw.com/jishu/585828.html
使用html5新特性轻松监听任何App自带返回键的示例 微信html5页面调用第三方位置导航的示例

游客 回复需填写必要信息