Please move the slider and study the readings.
 	
   
    <script>
    {
	    var canvas = document.getElementById('myCanvas');
	    var context = canvas.getContext('2d');
	    var a = 0, b;
	    function ver(a) {
	        a = eval(document.getElementById('ran').value);
	        context.clearRect(0, 0, 500, 400);
	        //main scale
	        context.beginPath();
	        context.moveTo(15, 100);
	        context.lineTo(450, 100);
	        context.lineTo(450, 150);
	        context.lineTo(50, 150);
	        context.lineTo(50, 200);
	        context.lineTo(40, 190);
	        context.lineTo(15, 160);
	        context.lineTo(15, 100);
	        context.closePath();
	        context.lineWidth = 2;
	        context.fillStyle = 'grey';
	        context.fill();
	        // main scale - numerals
	        context.font = 'bold 10pt Calibri';
	        context.fillStyle = 'black';
	        context.fillText(0, 48, 125);
	        context.fillText(1, 148, 125);
	        context.fillText(2, 248, 125);
	        context.fillText(3, 348, 125);
	        context.fillText('cm', 428, 125);
            // main scale - big ticks
	        for (var i = 50; i < 450; i = i + 100) {
	            context.beginPath();
	            context.moveTo(i, 130);
	            context.lineTo(i, 150);
	            context.strokeStyle = 'white';
	            context.stroke();
	        }
	        // main scale - small ticks
	        for (var i = 50; i < 450; i = i + 10) {
	            context.beginPath();
	            context.moveTo(i, 140);
	            context.lineTo(i, 150);
	            context.strokeStyle = 'white';
	            context.stroke();
	        }
	        //vernier scale
	        context.beginPath();
	        context.moveTo(50 + a, 150);
	        context.lineTo(150 + a, 150);
	        context.lineTo(150 + a, 200);
	        context.lineTo(50 + a, 200);
	        context.lineTo(50 + a, 150);
	        context.fillStyle = 'lightgrey';
	        context.fill();
	        // ticks
	        for (var i = 50; i <= 140; i = i + 9) {
	            context.beginPath();
	            context.moveTo(i + a, 150);
	            context.lineTo(i + a, 170);
	            context.strokeStyle = 'black';
	            context.stroke();
	            context.closePath();
	            // numerals
	            context.font = 'bold 8pt Calibri';
	            context.fillStyle = 'black';
	            context.fillText(0, 52 + a, 180);
	            context.fillText(5, 95 + a, 180);
	            context.fillText(10, 135 + a, 180);
	        }
	        //spring
	        context.beginPath();
	        context.moveTo(50, 165);
	        context.lineTo(50 + a, 165 + 2 * Math.sin(a));
	        context.lineWidth = 3;
	        context.strokeStyle = 'red';
	        context.stroke();
	        context.closePath();
	        // readings
	        context.font = '10pt Calibri';
	        context.fillStyle = 'blue';
	        context.fillText(a / 10 + ' mm', 50 + a / 2, 220);
	    }
	    window.onload = ver();
   
    </script>