A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: How to make fluid effect out of shape

  1. #1
    Senior Member
    Join Date
    Jul 2001
    Location
    Queensland Australia
    Posts
    283

    How to make fluid effect out of shape

    Hello Guys

    Im very new to flash MX 2004 pro and have been trying to do this with shape tweens and carnt get it to look fluid enough , I thought I would ask if there is an action script that could get a better look .

    If you imagine your stage is a side on view of a fish tank and the water(Shape)is at a low depth in the bottom and the water is rocking left to right like a wave , no interaction just the fluid movement Im after over time and looped .

    Any ideas on how to do this ?

    Thanks Rod

  2. #2
    Junior Member
    Join Date
    Jul 2004
    Posts
    7
    If you want it to look realistic, you can use a displacement equation for periodic motion, using AS. Create a movieclip for the fishtank, and add a function to it called waterDraw. Use setTimer to call a function which will calculate the time elapsed in seconds (using either Flash's built-in function, or your own counter) and passes this to the fish tank's waterDraw function. The fish tank's waterDraw function should look like this:

    function drawWater(t:Number)
    {
    lineStyle();
    beginFill(0x00FF00);
    moveTo(tankWidth, 0);
    lineTo(tankWidth, tankHeight);
    lineTo(0, tankHeight);
    lineTo(0, 0);
    for (var i:Number = 0; i <= ACCURACY; i++)
    {
    var x:Number = tankWidth * (i / ACCURACY);
    var y:Number = A * Math.cos(2 * Math.PI * (t / T - x / C));
    lineTo(x, y);
    }
    lineTo(tankWidth, 0);
    endFill();
    }

    Set ACCURACY to how many vertices you want the waves to be rendered with (I'd suggest like 100 or 150, depending on how big your tank is...). Be sure tankWidth and tankHeight are defined, or replace them with _width and _height. You may also need to offset y-coordinates, if you want to empty space at the top of the tank.
    Finally, the most important variables to set are the parameters of the periodic displacement equation. A is the amplitude (wave height) in pixels, T is the period of the wave (how long before it repeats itself), and C is the wave speed (in pixels/second, I think).

    Typically, real waves, especially large slow moving ones, have more of cusps than rounded tops... I think you might be able to get this effect by putting the Cos function inside of Pow(..., 2) or Pow(..., 4). It has to be an even power. You'll also need to adjust the other parameters to get it to look normal again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center