I would like to replicate a sine wave function as a spring that expand and contracts without losing its original wave structure, like the spring animation of a bouncing black box (not the red wave), found here. Í am able to draw a sine wave and edit its length but cannot keep the same structure of the sine wave.
Take a look at the animation at https://react-spring.io/#why-springs-and-not-durations
You can see that the spring expands and contracts without losing its wave form.
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var i;
for(i=0; i<360; i+= 20){
ctx.moveTo(i+5,180);
ctx.lineTo(i,180);
}
ctx.stroke();
var counter = 0, x=0,y=180;
//100 iterations
var increase = ((110/180)*(Math.PI / 3));
for(i=0; i<=270; i+=10){
ctx.moveTo(x,y);
x = i;
y = 180 - Math.sin(counter) * 113;
counter += increase;
ctx.lineTo(x,y);
ctx.stroke();
//alert( " x : " + x + " y : " + y + " increase : " + counter ) ;
}
<canvas id="myCanvas" width="360" height="360" style="border:1px solid #d3d3d3;">