window.onload = function() {
button = document.getElementById("button");
button.onclick = strokeCircle;
}
function strokeCircle() {
a = Math.random();
b = Math.random();
x = (45 * a) + ((640 - (45 * a))*a);
y = (45 * b) + ((400 - (45 * b))*b);
if (a >= b) {
z = (44 * b) + 1;
} else {
z =(44 * a) + 1;
}
canvas = document.getElementById("mycanvas");
ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.arc(x, y, z, 0,2*Math.PI, false);
ctx.stroke();
}
</script>
<p><input type="button" value="click" id="button"></p>
원하던 것은 원(1~45사이즈)이 캔버스를 벗어나지 않고 랜덤하게 그려지는 것입니다.
제가 머리가 나빠서 그런지 몇번을 시도해도 안되네요 ㅠㅠ
(지름 1의 원이라면 (1,1)에 위치 할 수 있어야 합니다.)