首頁 > web前端 > css教學 > 利用Canvas製作旋轉的太極範例分享

利用Canvas製作旋轉的太極範例分享

小云云
發布: 2018-03-12 09:52:02
原創
1582 人瀏覽過

好久沒動canvas了,今下午突然想回顧一下,就寫了個旋轉的太極,哈哈,蠻好玩的,在這裡就將自己寫的過程展示出來,旋轉使用的css實現的,沒有用canvas自己的,希望大佬們不要吐槽。本文主要和大家介紹了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();

登入後複製

效果

#相關推薦:

canvas製作滑鼠拖曳繪製圖形

使用Canvas製作時鐘動畫的方法

html5使用canvas製作彈幕功能實例講解

#

以上是利用Canvas製作旋轉的太極範例分享的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板