利用Canvas製作旋轉的太極樣本分享

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

效果

相關文章

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.