html5实现画图
<!doctype html>
<html>
<head>
<script type="text/javascript">
function init(){
var ctx=document.getElementById('c').getContext('2d');
//ctx.beginPath()和ctx.closePath()
ctx.beginPath();
//ctx.strokeStyle,ctx.fillStyle设置路线的颜色
ctx.strokeStyle="rgb(200,0,0)";
//画半圆
ctx.arc(200,200,50,0,Math.PI,true);Math.PI代表半圆
ctx.arc(200,200,50,0,Math.PI,false);
//画圆
//ctx.arc(200,200,50,0,2*Math.PI,true);
//ctx.arc(200,200,50,0,2*Math.PI,false);
ctx.arc(200,200,50,.5*Math.PI,2.5*Math.PI,false);
ctx.fillStyle="rgb(200,0,0)";
ctx.closePath();
//stroke()生成的是空心线条,fill()为填充
//ctx.stroke();
ctx.fill();
ctx.strokeStyle="rgb(255,0,0)";
ctx.lineWidth=5;
ctx.stroke();
}
</script>
</head>
<body>
<body onload='init();'>
<canvas id="c" width="400" height="300">
Your brower doesn't support the HTML5 element canvas.
</canvas>
</body>
</html>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。