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

投稿テスト ノイズ画面みたいなの

Get Adobe Flash player
by b_scribe 26 Jun 2010
    Embed
/**
 * Copyright b_scribe ( http://wonderfl.net/user/b_scribe )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/io93
 */

package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.geom.Matrix;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.filters.ColorMatrixFilter;
    import flash.text.TextField;
    
    public class parinTest extends Sprite {
        private var noiseBmp:Vector.<Bitmap> = null;
        private var nowNoiseNo:uint = 0;
        private var stripeBmd:BitmapData = null;
        private var enterCount:uint = 0;
        private var dtf:TextField = null;
        private const NOIZE_MAX_PTRN:uint = 10;
        
        public function parinTest() {
            // write as3 code here..
            this.dtf = new TextField();
            this.addChild(this.dtf);
            // 縦縞
            var ts:Shape = new Shape();
            var colors:Array = [0x000000,0xffffff,0xffffff,0x000000]; // 各ポイントの色
            var alphas:Array = [0,1,1,0];    // 各ポイントのアルファ
            var ratios:Array = [20,100,155,235]; // 各ポイントの位置
            var rotate:Number = 90;
            var radian:Number = rotate * Math.PI / 180;
            var gMatrix:Matrix = new Matrix();
            var stripeSize:Number = 8; // 縞のおおきさ?
            
            gMatrix.createGradientBox(stripeSize,stripeSize,radian,0,0);
            ts.graphics.beginGradientFill(GradientType.LINEAR , colors,alphas,ratios,gMatrix,SpreadMethod.REFLECT);
            ts.graphics.drawRect(0,0,this.stage.stageWidth,this.stage.stageHeight);
            this.stripeBmd = new BitmapData(this.stage.stageWidth,this.stage.stageHeight,true,0x00000000);
            
            this.stripeBmd.draw(ts);
            this.noiseBmp = new Vector.<Bitmap>();
            
            // ノイズbmp製作フレームへ
            this.addEventListener(Event.ENTER_FRAME , this.onEnterFrame_createPerlinNoize);
        }
        
        private function onEnterFrame_createPerlinNoize(evt:Event):void{
            var seed:Number = Math.floor(Math.random() * 1000);
            var bpos:Point = new Point(0,0);
            var newNoizeBmd:BitmapData = new BitmapData(this.stage.stageWidth,this.stage.stageHeight , true,0x00000000);
            newNoizeBmd.perlinNoise(3,3,1,seed,true,false,7,true,null);
            
            var margeBmd:BitmapData = new BitmapData(this.stage.stageWidth,this.stage.stageHeight,false,0xff000000);
            margeBmd.copyPixels(newNoizeBmd,margeBmd.rect,bpos,this.stripeBmd,bpos,true);
            
            // グレースケールにオフセットで色を乗せて黒へ着色してみる
            var cMatrix:ColorMatrixFilter = new ColorMatrixFilter([
                                                                     1,0,0,0,0x2e,
                                                                     0,1,0,0,0x41,
                                                                     0,0,1,0,0x3d,
                                                                     0,0,0,1,0x00,
                                                                  ]);
            margeBmd.applyFilter(margeBmd , margeBmd.rect , bpos , cMatrix);
            this.noiseBmp.push(new Bitmap(margeBmd,"auto",true));
            
            this.dtf.text = "count:" + this.noiseBmp.length + "\n";
            if(this.noiseBmp.length == 1){
                this.addChildAt(this.noiseBmp[0],0);
            }
            else if(this.noiseBmp.length >= this.NOIZE_MAX_PTRN){
                this.removeEventListener(Event.ENTER_FRAME , this.onEnterFrame_createPerlinNoize);
                this.addEventListener(Event.ENTER_FRAME , this.onEnterFrame_swapBitmap);
                this.dtf.appendText("CountEnd:" + this.noiseBmp.length);
            }
            else {
                this.onEnterFrame_swapBitmap();
            }
        }
        private function onEnterFrame_swapBitmap(evt:Event = null):void{
            this.nowNoiseNo ++;
            if(this.nowNoiseNo >= this.noiseBmp.length){
                this.nowNoiseNo = 0;
            }

            this.removeChildAt(0);
            this.addChildAt(this.noiseBmp[this.nowNoiseNo],0);
        }

    }
}