moveTo() Method - Javascript Canvas Reference

Javascript examples for Canvas Reference:moveTo

Description

The moveTo() method moves the path to a point in the canvas without creating a line.

JavaScript syntax

context.moveTo(x, y);

Parameter Values

Parameter Description
x The x-coordinate of where to move
y The y-coordinate of where to move

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="300" height="250" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>

<script>

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();//from  ww w.  ja v a2 s  .c o m
ctx.moveTo(0, 0);
ctx.lineTo(300, 150);

ctx.moveTo(200, 110);
ctx.lineTo(300, 250);
ctx.stroke();

</script>

</body>
</html>

Related Tutorials