The vertex of the right-angled triangle moves along the circumference of the circle in such a way that its hypotenuse remains a diameter of the circle throughout.
<script type = 'text/javascript' >
var canvas = document.getElementById('Canvas_Six');
var ctx= canvas.getContext('2d');
var x,y,i=0;
function draw(){
i=i+0.25;
if (i==360){i=0;}
var hor=140*Math.cos(i),ver=140*Math.sin(i);
x=200+hor; y=200+ver;
var a = Math.round(Math.pow((Math.pow(140-hor,2) + Math.pow(ver,2)),0.5));
var b = Math.round(Math.pow((Math.pow(140+hor,2) + Math.pow(ver,2)),0.5));
ctx.clearRect(0,0,400,400);
ctx.beginPath();
// Red circle
ctx.arc(200,200,140,0,2*Math.PI);
ctx.strokeStyle="red";
ctx.lineWidth=3;
ctx.stroke();
ctx.beginPath();
// green line
ctx.moveTo(60,200);
ctx.lineTo(x,y);
ctx.lineWidth=2;
ctx.strokeStyle="green";
ctx.stroke();
//yellow line
ctx.beginPath();
ctx.moveTo(340,200);
ctx.lineTo(x,y);
ctx.lineWidth=2;
ctx.strokeStyle="yellow";
ctx.stroke();
ctx.beginPath();
ctx.moveTo(60,200);
ctx.lineTo(340,200);
ctx.lineWidth=2;
ctx.strokeStyle="blue";
ctx.stroke();
ctx.beginPath();
ctx.font="20px verdana";
ctx.fillText('a = ' + a,20,335);
ctx.fillStyle="green";
ctx.fill();
ctx.beginPath();
ctx.font="20px verdana";
ctx.fillText('b = ' + b,20,360);
ctx.fillStyle="yellow";
ctx.fill();
/*ctx.beginPath();
ctx.font="20px verdana";
ctx.fillText('c = ' + 300,20,380);
ctx.fillStyle="blue";
ctx.fill();*/
}
window.setInterval('draw()',1000);
</script>
All Canvas Animations