In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

DisplacementMapFilterの練習2 ボヨンボヨン

/**
 * Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iO3T
 */

package {
    import flash.display.*;
    import flash.geom.*;
    import flash.utils.*;
    import flash.events.*;
    import flash.display.MovieClip;
    import flash.geom.Point;
    import flash.utils.Timer;
    import flash.filters.DisplacementMapFilterMode;
    import flash.filters.DisplacementMapFilter;
    
     [SWF(width=465,height=465,backgroundColor=0xffffff,frameRate=45)]
    
    import flash.filters.BevelFilter;
    
    public class FlashTest extends Sprite {
        
        public var w:Number=465;
        public var h:Number=465;
        public var shape:Ball;
        
        public var bmpd:BitmapData;
        public var bmp:Bitmap;
        public var ctf:ColorTransform;
        public var mtx:Matrix;
        public var bevel:BevelFilter;
        public var myDisplacementMap:DisplacementMapFilter;
        
        //perlinNoise用パラメーター
        public var rate:Number;
        public var octave:uint;
        public var ramdomSeed:int;
        public var stitch:Boolean;
        public var fractal:Boolean;
        public var channelOptions:uint;
        public var grayScale:Boolean;
        public var offsets:Array;
        public var v:int;
        public var pointA:Point;
        public var pointB:Point;
        public var vx:Number=0;
        
        //DisplacementMapFilter用パラメーター       
        public var mapPoint:Point;
        public var mapX:uint;
        public var mapY:uint;
        public var mapScaleX:Number;
        public var mapScaleY:Number;
        public var mode:String;
        public var mapColorChannel:uint;
     
     
        public function FlashTest() {
            // write as3 code here..
            init();
            
        }
        
       
        public function init():void{
            
            //背景を作る
            graphics.lineStyle(105,0xfcaaff);
            graphics.beginFill(0xffffff,1);            
            graphics.drawRect(0,0,w,h);
            graphics.endFill();
            
            //ボールを作る
            shape=new Ball(0xefefff,0x215dd4,0xdfffac,180);
            addChild(shape);
            shape.x=w/2;
            shape.y=h/2;
                 
            //ビットマップデータとビットマップを作る
            bmpd = new BitmapData(shape.width,shape.height,false,0xffffff);
            bevel=new BevelFilter(20,120,0xdddddd,0.6,0x111162,0.6,45,45);
            bmpd.generateFilterRect(bmpd.rect,bevel);
            bmp=new Bitmap(bmpd);    
            
            //フィルター用配列を作る
            filters=new Array();
            
            //perlinNoise用パラメーターを作る
            rate=1/20;
            octave=2;
            ramdomSeed=20;
            stitch=false;
            fractal=true;
            channelOptions=7;
            grayScale=false;
            //offsets=new Array();
            //pointA=new Point(v,0);
            //pointB=new Point(v,0);
            offsets=["pointA","pointB"];
            
            //DisplacementMapFilter用パラメーターを作る
            mapPoint=new Point(0,0);
            mapX=BitmapDataChannel.GREEN;
            mapY=BitmapDataChannel.BLUE;
            mapScaleX=100;
            mapScaleY=100;
            mode=DisplacementMapFilterMode.COLOR;
            
            addEventListener(Event.ENTER_FRAME,wave);           
           
        }
        
        public function wave(e:Event):void{
           
           //ビットマップデータにノイズを設定
           bmpd.perlinNoise(shape.width,shape.height,octave,ramdomSeed,stitch,fractal,channelOptions,grayScale,[new Point(0,v),new Point(0,v)]);     
           //DisplacementMapFilterにperlinNoiseをかけたbmpdを設定
           myDisplacementMap=new DisplacementMapFilter(bmpd,mapPoint,mapX,mapY,mapScaleX,mapScaleY,mode,0xf18a92,0);
           //ボールにフィルターを設定
           shape.filters=[myDisplacementMap,bevel];
           v+=10;
           
    
        }
    
    }
}


import flash.display.*;
import flash.geom.Matrix;

class Ball extends Sprite{
    
    public var type:String;
    public var colors:Array;
    public var alphas:Array;
    public var rations:Array;
    public var spread:String;
    public var interpolation:String;
    public var focalPoint:Number;
    public var mtx:Matrix;
    
    public function Ball(color1:uint,color2:uint,lineColor:uint,r:Number){
        
        //グラデーションのパラメーターを作る
        //引数1
        type=GradientType.RADIAL;
        //引数2
        colors=[color1,color2];
        //引数3
        alphas=[1,1]
        //引数4
        rations=[0,255];
        //引数5
        mtx=new Matrix();
        mtx.createGradientBox(2*r,2*r,0,0,0);//幅、高さ、方向を指定する角度、水平移動ピクセル数、垂直移動ピクセル数
        mtx.translate(-r,-r);//グラデーションの開始位置を中心にもってくる
        mtx.rotate(Math.PI/4);
        //引数6
        spread=SpreadMethod.PAD;
        //引数7
        interpolation="rgb"
        //引数8
        focalPoint=0//グラデーションの焦点の位置
        
        graphics.beginGradientFill(type,colors,alphas,rations,mtx,spread,interpolation,focalPoint);
        
        //図形を描く
        //graphics.lineStyle(1,lineColor);
        graphics.drawCircle(0,0,r);
        graphics.endFill();        
        
    }
    
}