canvas繪製多個圓圈效果

admin發表於2018-06-05
分享一段程式碼例項,它實現了利用canvas繪製多個圓圈的效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼執行程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<script>
window.onload = function () {
  draw()
}
function draw() {
  var canvas = document.getElementById("canvas");
  if(canvas == null){
    return false;
  }
  var context = canvas.getContext('2d');
  context.fillStyle = "#eeeeff";
  context.fillRect(0,0,400,300);
  var n = 0;
  for (var index = 0 ; index < 10; index++) {
    context.beginPath();
    context.arc(index * 25, index * 25, index * 10, 0, Math.PI * 2, true);
    context.closePath();
    context.fillStyle = 'rgba(255,0,0,0.25)';
    context.fill();
  }
}
</script>
</head>
<body>
<canvas id="canvas" width="400" height="300"></canvas>
</body>
</html>

相關文章