Use canvas to create rotating Taiji sample sharing

Source: Internet
Author: User
Long time no move canvas, this afternoon suddenly want to review, wrote a rotation of Tai chi, haha, quite fun, in here will write their own process to show out, rotate the use of CSS implementation, not with canvas their own, I hope the big boys do not spit groove. This article mainly introduces the data of the example of canvas making rotating taiji, hoping to help everyone.

Objective

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= "height=" ></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

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.