Let’s draw something on our canvas in order to make it useful to our users. We’ll draw a simple line for this example.

<script>

function drawLine()

{

var myCanvas = document.getElementById('canvas');

var myContext = canvas.getContext('2d');

myContext.beginPath();

myContext.moveTo(30, 90);

myContext.lineTo(90, 30);

myContext.stroke();

}

window.addEventListener("load", drawLine, true);

</script>

This code is not overly complicated if you already know JavaScript. However, if you are new to JavaScript then you may read about it online. In brief, we set two points on our canvas and called on stroke() method to draw a line between two points.