<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>图形组合</title>
<script>
function draw(id)
{
var canvas=document.getElementById(id);
if(canvas==null)
{
return false;
}
var context=canvas.getContext("2d");
//重点
var oprtns=new Array(
"source-atop",
"source-in",
"source-out",
"source-over",
"destination-atop",
"destination-in",
"destination-out",
"destination-over",
"lighter",
"copy",
"xor"
);
i=8;
//矩形
content.fillStyle="blue";
content.fillRext(10,10,60,60);
content.globalCompositeOperation=oprtns[i];//重叠位置
content.beginPath();
//圆形
content.fillStyle"red";
content.arc(60,60,30,Math.PI*2,false);
content.fill();
}
</script>
</head>
<body onload="draw("canvas");">
<canvas id="canvas" width="500" height="500"></canvas>
</body>
</html>