我正在閱讀Javascript for Kids作者:Nick Morgan我製作了下面的代碼。現在JavaScript Canvas翻譯y軸
<!DOCTYPE html>
<html>
<head>
<title>Canvas Animation</title>
</head>
<body>
<canvas id ="canvas" width ="200" height="200"></canvas>
<script>
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
var circle = function (x, y, radius, fillCircle) {
ctx.beginPath();
ctx.arc(x, y, radius, 0, Math.PI * 2, false);
if (fillCircle) {
ctx.fill();
}
else {
ctx.stroke();
}
}
var drawBee = function (x, y) {
ctx.lineWidth = 2;
ctx.strokeStyle = "Black";
ctx.fillStyle = "Gold";
circle(x, y, 8, true);
circle(x, y, 8, false);
circle(x - 5, y - 11, 5, false);
circle(x + 5, y - 11, 5, false);
circle(x - 2, y - 1, 2, false);
circle(x + 2, y - 1, 2, false);
}
</script>
</body>
</html>
,我創建了一個名爲circle
繪製某些圈子的功能,我想創建兩個圓圈與上面值x和y的原圓心黑色輪廓。
正如你所看到的,這些圈子讓代碼
circle(x - 5, y - 11, 5, false);
circle(x + 5, y - 11, 5, false);
但我認爲類似的地方向右移動在正方向x軸x + 5
,我覺得移動了 y軸正向標度軸爲y + 11
。
爲什麼它是y - 11
而不是y + 11
?
哇的一瞬間就進入了我的腦海!我現在明白非常感謝! –