Canvas制作旋轉(zhuǎn)的太極的示例
發(fā)布時(shí)間:2018-03-09 16:02:41 作者:騎著毛驢逗你玩兒
我要評(píng)論
這篇文章主要介紹了Canvas制作旋轉(zhuǎn)的太極的示例的相關(guān)資料,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
前言
好久沒(méi)動(dòng)canvas了,今下午突然想回顧一下,就寫(xiě)了個(gè)旋轉(zhuǎn)的太極,哈哈,蠻好玩的,在這里就將自己寫(xiě)的過(guò)程展示出來(lái),旋轉(zhuǎn)使用的css實(shí)現(xiàn)的,沒(méi)有用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();
效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
HTML5 Canvas旋轉(zhuǎn)動(dòng)畫(huà)的2個(gè)代碼例子(一個(gè)旋轉(zhuǎn)的太極圖效果)
這篇文章主要介紹了HTML5 Canvas旋轉(zhuǎn)動(dòng)畫(huà)的2個(gè)代碼例子,實(shí)現(xiàn)了一個(gè)旋轉(zhuǎn)的太極圖效果,學(xué)習(xí)HTML5 Canvas旋轉(zhuǎn)動(dòng)畫(huà)的朋友可以參考下2014-04-10- 這篇文章主要介紹了canvas繪制太極圖的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)2020-04-29

