0
如何繪製與此代碼水平對齊的多個圓?我嘗試了一個循環,但無濟於事。水平繪製多個圓HTML5
<!doctype html>
<html>
<head>
<title> Draw circle </title>
<body>
<canvas id="myCanvas" width="500" height="300" style="border:solid 2px white;">
</canvas>
<script>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
function draw_circle (circleX, circleY, radius, fill) {
context.fillStyle = "black";
context.fillRect(0, 0, 500, 300);
context.strokeStyle = "red";
context.strokeRect(5, 5, 490, 290);
context.fillStyle = fill;
context.arc(circleX, circleY, radius, 0, Math.PI*2);
context.fill();
}
draw_circle(100, 100, 30 , "cyan");
</script>
</body>
</html>
你'draw_circle'功能填充黑色每次調用時在畫布上。你應該只運行一次該代碼。 – EvilZebra 2014-10-20 19:40:00
明白了,謝謝您的更正:) – Drew 2014-10-20 20:07:57