I believe that you are looking for something like this:
draw(0); $('#range').on('change', function(){ range = parseInt($(this).val()); draw(range) }) function draw(val){ var canvas = document.getElementById('canvas'); var context = canvas.getContext('2d'), x = 100, y = 50, d; context.clearRect(0, 0, canvas.width, canvas.height); d = Math.sqrt(Math.pow(val,2) + Math.pow(50,2)); context.beginPath(); context.lineWidth = 1; context.arc(x,y+val,d,0,2*Math.PI);
Working example
There are several drawbacks to this: it becomes โslowerโ the closer you get to the circle, because the circle becomes exponentially larger in the hidden section (the slider controls its size), and that it does not work for diagonal lines, as it is now.
Other than that, it works as expected.
source share