0
저는 캔버스에 5 각형 그림이 하나 있습니다. 마우스를 클릭 한 위치로 옮기고 싶습니다.클릭하면 어떻게 캔버스 그림을 움직입니까?
CODE
<canvas id="fld" width="1000px" height="800"></canvas>
<script type="text/javascript"><!--
onload = function() { draw(); };
function draw() {
var canvas = document.getElementById('fld');
if (! canvas || ! canvas.getContext) {return false;}
var ctx = canvas.getContext('2d');
//Pentagon
ctx.beginPath();
ctx.strokeStyle = 'rgb(255, 0, 0)';
ctx.moveTo(100,10);
for (var i=1;i<=5; ++i) {
th=i * 2 * Math.PI/5;
x=100+90*Math.sin(th);
y=100-90*Math.cos(th);
ctx.lineTo(x,y);
}
ctx.stroke();
ctx.beginPath();
ctx.arc(900, 60, 40, 0, 2 * Math.PI, false);
ctx.fillStyle = "rgb(255, 0, 0)";
ctx.fill();
ctx.strokeStyle = "black";
ctx.stroke();
}
</script>