<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#myCanvas {
border: 10px solid cyan;
background-color: cyan;
}
</style>
</head>
<body>
<canvas id="myCanvas" width="600" height="600"></canvas>
</body>
<script type="text/javascript">
var myCanvas = document.getElementById("myCanvas");
var context = myCanvas.getContext("2d");
var deg = Math.PI/180;
function draw (x,y,color) {
context.beginPath();
context.fillStyle = color;
context.arc(x,y,30,0,360*deg,false);
context.fill()
}
context.translate(300,300);
setInterval(function () {
context.clearRect(-300,-300,600,600);
context.rotate(3*deg);
draw(150,150,"black");
draw(-150,-150,"white");
},20)
</script>
</html>
网友评论