Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
60 lines (48 sloc) 1.13 KB
<!doctype html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
<title>画圆和扇形</title>
<style type="text/css">
body{background: black}
#c1{background:white;}
span{color:white;}
</style>
</head>
<body>
<canvas id="c1" width="400" height="400">
<span>不支持canvas的浏览器就会显示</span>
</canvas>
<script type="text/javascript">
window.onload = function(){
var oc = document.getElementById('c1');
var content = oc.getContext('2d');
var num = 0;
var num2 = 0;
var value = 1;
//translate(x,y)
content.translate(100,100);
//content.rotate(45*Math.PI/180);
//scale(宽比,高比);
//content.scale(2,2);
//content.fillRect(0,0,100,100);
setInterval(function(){
num++;
content.save();
content.clearRect(-100,-100,oc.width,oc.height);
if(num2 == 100){
value = -1;
}else if(num2 == 0){
value = 1;
}
num2 += value;
content.scale(num2*1/50,num2*1/50);
content.rotate(num*Math.PI/180);
content.translate(-50,-50);
content.fillRect(0,0,100,100);
content.restore();
},30);
}
</script>
</body>
</html>
You can’t perform that action at this time.