分类分类
更新时间:2026-08-08 19:59:37作者:zy
前言
好久没动canvas了,今下午突然想回顾一下,就写了个旋转的太极,哈哈,蛮好玩的,在这里就将自己写的过程展示出来,旋转使用的css实现的,没有用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-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();
效果

以上就是本文的全部内容,希望对大家的学习有所帮助。
相关
星球小队策略游戏316.49 MBv1.15.366.638912026-08-08
下载超市大亨3D经营养成253.14 MBv10.252026-08-08
下载绝世武林角色扮演453.09 MBv1.8.14162026-08-08
下载Crush Crush手机版经营养成124.86 Mv0.4482026-08-08
下载消消大亨经营养成13.56 Mv1.0.02026-08-08
下载endacopia手机版冒险游戏1.43Gv1.0.02026-08-08
下载最强帮主角色扮演143.91 MBv9991.12026-08-08
下载战西游手游折扣版策略游戏13.77 MBv1.02026-08-08
下载富豪物语创业时代官方版经营养成215.01 Mv3.0.12026-08-08
下载咒术回战爱憎乱斗手游动作射击291.7 Mv1.0.02026-08-08
下载三国吧兄弟折扣版策略游戏380.04 MBv1.0.02026-08-08
下载代号97动作射击277.47 Mv1.0.72026-08-08
下载










