Click and drag a bit. Then watch.
Other version 1
Other version 2
friction = .8;
yOffset = 200; //for display purposes only
numNodes = 100; //count of points
Width = 550; //width of display
drag = false;
points = [];
for(i = 0; i < numNodes+2; ++i){
o = new Object();
o.y = 0;
o.yV = 0;
points.push(o);
}
this.onEnterFrame = function(){
clear();
lineStyle(0,0);
beginFill(0);
moveTo(-1,yOffset);
for(i = 1; i <= numNodes; ++i){
avg = (points[i-1].y+points[i+1].y)/2;
points[i].yV += (avg-points[i].y)/2;
points[i].yV *= friction;
points[i].y += points[i].yV;
lineTo((i-1)*Width/numNodes,points[i].y+yOffset);
}
lineTo(Width,yOffset);
lineTo(551,401);
lineTo(-1,401);
lineTo(-1,yOffset);
if(drag){
el = Math.floor(_xmouse*numNodes/Width+1);
if(el < 1)
el = 1;
else if(el > numNodes)
el = numNodes;
points[el].y = _ymouse-yOffset;
points[el].yV = 0;
}
}
this.onMouseDown = function(){
drag = true;
}
this.onMouseUp = function(){
drag = false;
}