HTML5画布CANVAS动画。

就剩那两个大半圆不知道怎么用代码表示了,求大神给看下,怎么设置的才可以以自己的圆心来转。实现旋转的八卦。不能上传视频,有个转的过程图,在最下面。

<!DOCTYPE HTML>

<html>

<head>

<meta charset="utf-8">

<title></title>

</head>

<body>

<canvas id="myCanvas" width="500" height="500">your browser does not support the canvas tag</canvas>

<script type="text/javascript">

var deg1=0.0;

var deg2=0.0;

var deg3=0.0;

var deg4=0.0;

var deg5=0.0;

var deg6=0.0;

setInterval(drawCircle,40);

function drawCircle() {

var canvas = document.getElementById('myCanvas');

var context = canvas.getContext('2d');

context.clearRect(0, 0, 500, 500);

context.beginPath();

context.fillStyle = "black";

var px =Math.sin(deg5)*100;

var py =Math.cos(deg5)*100;

context.arc(300+px,300-py,200,1.5*Math.PI,0.5*Math.PI,true);

context.fill();

deg5 +=0.05;   //黑色大半圆


context.beginPath();

context.fillStyle = "red";

var px =Math.sin(deg6)*100;

var py =Math.cos(deg6)*100;

context.arc(300+px,300-py,200,0.5*Math.PI,1.5*Math.PI,true);

context.fill();

deg6 +=0.05;   //红色大半圆


context.beginPath();

context.fillStyle = "red";

var px =Math.sin(deg4)*100;

var py =Math.cos(deg4)*100;

context.arc(300-px,300+py,100,0,2*Math.PI,true);

context.fill();

deg4 +=0.05;  //红色中圆


context.beginPath();

context.fillStyle = "black";

var px =Math.sin(deg2)*100;

var py =Math.cos(deg2)*100;

context.arc(300-px,300+py,25,0,2*Math.PI,true);

context.fill();

deg2 +=0.05;  //黑色中圆


context.beginPath();

context.fillStyle = "black";

var px =Math.sin(deg3)*100;

var py =Math.cos(deg3)*100;

context.arc(300+px,300-py,100,0,2*Math.PI,true);

context.fill();

deg3 +=0.05;  // 黑色小圆


context.beginPath();

context.fillStyle = "red";

var px =Math.sin(deg1)*100;

var py =Math.cos(deg1)*100;

context.arc(300+px,300-py,25,0,2*Math.PI,true);

context.fill();

deg1 +=0.05;  //红色小圆

}

</script>

</body>

</html>

56fa624a00018d9d03850362.jpg

56fa624a0001ba1803690345.jpg


qq_控心_0
浏览 1642回答 1
1回答

qq_控心_0

已经知道了。嘿嘿。
打开App,查看更多内容
随时随地看视频慕课网APP