Canvas制作旋转太极的动画


本文摘自PHP中文网,作者php中世界最好的语言,侵删。

这次给大家带来Canvas制作旋转太极的动画,Canvas制作旋转太极动画的注意事项有哪些,下面就是实战案例,一起来看一下。

前言

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

css

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

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

1

2

3

<body>

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

</body>

js

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

let ctx = document

    .getElementById("canvas")

    .getContext("2d");

// left-black-big

ctx.beginPath();

ctx.fillStyle = "#000";

ctx.arc(250,250,200,Math.PI/2,Math.PI*1.5,false);

ctx.closePath();

ctx.fill();

// right-white-big

ctx.beginPath();

ctx.fillStyle = "#fff";

ctx.arc(250,250,200,Math.PI/2,Math.PI*1.5,true);

ctx.closePath();

ctx.fill();

// top-black-middle

ctx.beginPath();

ctx.fillStyle = "#000";

ctx.arc(250,150,100,Math.PI/2,Math.PI*1.5,true);

ctx.closePath();

ctx.fill();

// bottom-white-middle

ctx.beginPath();

ctx.fillStyle = "#fff";

ctx.arc(250,350,100,Math.PI/2,Math.PI*1.5,false);

ctx.closePath();

ctx.fill();

// top-white-small

ctx.beginPath();

ctx.fillStyle = "#fff";

ctx.arc(250,150,25,0,Math.PI*2);

ctx.closePath();

ctx.fill();

// bottom-black-small

ctx.beginPath();

ctx.fillStyle = "#000";

ctx.arc(250,350,25,0,Math.PI*2);

ctx.closePath();

ctx.fill();

效果

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

H5中APP监听返回事件处理

h5实现多图片预览上传及点击可拖拽控件

以上就是Canvas制作旋转太极的动画的详细内容,更多文章请关注木庄网络博客

相关阅读 >>

html5 canvas实现画直线与设置线条的样式

h5 canvas api中drawimage(图像进行缩放或裁剪)的使用实例

怎样用h5 canvas实现3d动态chart图表

关于html5如何在canvas中插入图片的示例详解

使用html5 canvas api中的clip()方法裁剪区域图像

canvas怎么使用

html5 canvas绘制五角星的方法

用html实现简单动画

animation-fill-mode属性怎么用

animation-play-state属性怎么用

更多相关阅读请进入《canvas》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...