PDA

View Full Version : Draw points with mouse coordinates



giotis
12-08-2012, 03:24 AM
Hi!
I'm searching for tutorials but I can not find them, I want this:
"When a user click in the canvas, draw that point."
How can I do that?
I have the mouse coordinates, but now? For example:


<script>
jQuery(document).ready(function(){
$("#canvas").click(function(e){
$('#mouse_coord').html(e.pageX +', '+ e.pageY);
});
})
</script>
<body>

<canvas id="canvas" style="border: none;" width="700" height="500"></canvas>
<div id="mouse_coord"></div>
</body>

How can I put this coordinates into my canvas?

Then, if a user draw more points, I would like to draw a poligon with a line that link the vertices.
Can you please tell me how can I do that?