Canvas: An Example of the rotation of Taiji.

Source: Internet
Author: User

Canvas: An Example of the rotation of Taiji.

Preface

I haven't moved canvas for a long time. I suddenly wanted to review it this afternoon. I wrote a rotating tai chi. Haha, it's fun. Here I will show my own writing process, the css used for rotation is not implemented by the canvas itself. I hope that the big players will not speak out.

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();

Effect

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.