<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<canvas id="myCanvas" style="border:solid 1px;" width="300" height="300"></canvas>
<script type="text/javascript">
function draw(){
var ctx = document.getElementById("myCanvas").getContext("2d");
ctx.fillStyle="black";
ctx.fillRect(0,0,300,300);
ctx.fill();
// 绘制圆形
ctx.beginPath();
ctx.arc(150,150,130,0,Math.PI*2,true);
ctx.clip();
// 变换
ctx.translate(200,20);
for(var i = 0;i<90;i++){
ctx.save();
ctx.transform(0.95,0,0,0.95,30,30);
ctx.rotate(Math.PI/12);
ctx.beginPath();
ctx.fillStyle="red";
ctx.globalAlpha="0.4";
ctx.arc(0,0,50,0,Math.PI*2,true);
ctx.closePath();
ctx.fill();
}
}
window.onload = function(){
draw();
}
</script>
</body>
</html>
html5 canvas学习--裁切路径
最新推荐文章于 2023-06-02 12:58:15 发布