`

[转]逼真的水波倒影

阅读更多
package
{
    import flash.display.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.geom.*;

    dynamic public class MainTimeline extends MovieClip
    {
        public var mc:MovieClip;
        public var bmd:BitmapData;
        public var bmd1:BitmapData;
        public var m1:Matrix;
        public var bmd2:BitmapData;
        public var shape:Shape;
        public var fillType:String;
        public var colors:Array;
        public var alphas:Array;
        public var ratios:Array;
        public var matr:Matrix;
        public var spreadMethod:String;
        public var seed:Number;
        public var point1:Point;
        public var point2:Point;
        public var bm:Bitmap;
        public var bm1:Bitmap;
        public var dmf:DisplacementMapFilter;

        public function MainTimeline()
        {
            addFrameScript(0, this.frame1);
            
        }

        public function frame(param1:Event) : void
        {
            this.bmd1.perlinNoise(this.mc.width / 3, this.mc.height / 3, 3, this.seed, true, true, 1, true, new Array(this.point1, this.point2));
            this.bm.filters = [this.dmf];
            this.point1.y = this.point1.y + 5;
            this.point2.y = this.point2.y + 2;
            if (this.point1.y > 10000)
            {
                this.point1.y = 0;
                this.point2.y = 0;
            }
           
        }

        function frame1()
        {
            this.bmd = new BitmapData(this.mc.width, this.mc.height, true, 0);
            this.bmd1 = new BitmapData(this.mc.width, this.mc.height);
            this.m1 = new Matrix();
            this.m1 = this.mc.transform.matrix.clone();
            this.bmd2 = new BitmapData(this.mc.width, this.mc.height, true, 0);
            this.shape = new Shape();
            this.fillType = GradientType.LINEAR;
            this.colors = [0, 0];
            this.alphas = [0, 1];
            this.ratios = [0, 255];
            this.matr = new Matrix();
            this.matr.createGradientBox(this.mc.width, this.mc.height, 90 * Math.PI / 180, 0, 0);
            this.spreadMethod = SpreadMethod.PAD;
            this.shape.graphics.beginGradientFill(this.fillType, this.colors, this.alphas, this.ratios, this.matr, this.spreadMethod);
            this.shape.graphics.drawRect(0, 0, this.mc.width, this.mc.height);
            this.bmd2.draw(this.shape);
            this.m1.d = this.m1.d * -1;
            this.m1.tx = 0;
            this.m1.ty = this.mc.height;
            this.bmd.draw(this.mc, this.m1);
            this.bmd.copyPixels(this.bmd2, this.bmd2.rect, new Point(0, 0), this.bmd, new Point(0, 0), true);
            this.seed = Math.floor(Math.random() * 5);
            this.point1 = new Point(0, 0);
            this.point2 = new Point(0, 0);
            this.bm = new Bitmap(this.bmd);
            this.bm1 = new Bitmap(this.bmd1);
            this.dmf = new DisplacementMapFilter(this.bmd1, new Point(0, 0), 1, 1, 10, 20, "color", 0, 0);
            addEventListener(Event.ENTER_FRAME, this.frame);
            addChild(this.bm);
            this.bm.x = this.mc.x;
            this.bm.y = this.mc.y + this.mc.height - 2;
        }

    }
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics