canvas繪製橢圓效果程式碼例項

admin發表於2017-02-20
分享一段程式碼例項,它實現了利用canvas繪製橢圓的效果。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
canvas {
  border:1px solid #d3d3d3
}
</style>
<script>
window.onload = function () {
  var c = document.getElementById("myCanvas");
  var ctx = c.getContext("2d");
  var w = 60, h = 80, b = h / w;
  ctx.translate(300, 100);
  ctx.scale(1, b);
  ctx.arc(0, 0, w / 2, 0, Math.PI * 2);
  ctx.stroke();
}
</script>
</head>
<body>
<canvas id="myCanvas" width="600" height="250"></canvas>
</body>
</html>

相關文章