This is supposed to be a self-regulating version, where the area of the black region is always the same as the white region. It works pretty well now but it took some tweaking to get it to where it wouldn't go crazy trying to correct itself.
friction = .78; pressure = .0000001; yOffset = 200; //for display purposes only numNodes = 100; //count of points Width = 550; //width of display totalDiff = 0; avgDiff = 0; 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 -= Math.abs(Math.pow(points[i].y,3))*avgDiff*pressure; points[i].yV *= friction; points[i].y += points[i].yV; totalDiff += points[i].y; lineTo((i-1)*Width/numNodes,points[i].y+yOffset); } lineTo(Width,yOffset); lineTo(551,401); lineTo(-1,401); lineTo(-1,yOffset); avgDiff = totalDiff/numNodes; totalDiff = 0; if(drag && _ymouse >= 0 && _ymouse <= 400){ 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; }