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

Noise (2)

//////////////////////////////////////////////////////////////////////////////
Noise (2)
BitmapDataでノイズ生成 (1)
http://www.project-nya.jp/modules/weblog/details.php?blog_id=477
[AS3.0] Noiseクラスに挑戦!
http://www.project-nya.jp/modules/weblog/details.php?blog_id=1113
//////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 10 Jul 2010
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/9nVn
 */

////////////////////////////////////////////////////////////////////////////////
// Noise (2)
//
// BitmapDataでノイズ生成 (1)
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=477
// [AS3.0] Noiseクラスに挑戦!
// http://www.project-nya.jp/modules/weblog/details.php?blog_id=1113
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.display.Bitmap;
    import flash.geom.Rectangle;
    import flash.events.Event;
    import flash.filters.BlurFilter;

    [SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var noise:Noise;
        private var label:Label;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            var rect:Rectangle = new Rectangle(0, 0, 445, 445);
            //ノイズ生成
            noise = new Noise(rect, false, 1 | 2 | 4);
            var bitmap:Bitmap = new Bitmap(noise);
            addChild(bitmap);
            bitmap.x = 10;
            bitmap.y = 10;
            //ラベル生成
            label = new Label(100, 60);
            addChild(label);
            label.text = "Noise";
            label.textColor = 0xFFFFFF;
            label.x = 232;
            label.y = 200;
            addEventListener(Event.ENTER_FRAME, update, false, 0, true);
        }
        private function update(evt:Event):void {
            //ノイズ生成
            noise.create(uint(Math.random()*1000));
            //ラベル動き
            var px:Number = Math.random()*32 - 16;
            var py:Number = Math.random()*32 - 16;
            label.x = 232 + px;
            label.y = 200 + py;
            label.filters = [new BlurFilter(uint(px) >> 1, uint(py) >> 1, 3)];
        }

    }

}


import flash.display.BitmapData;
import flash.geom.Rectangle;

class Noise extends BitmapData {
    private var seed:uint;
    private static var low:uint = 0;
    private static var high:uint = 255;
    private var channel:uint = 0;
    private var grayScale:Boolean = true;

    public function Noise(rect:Rectangle, g:Boolean = true, c:uint = 0, s:uint = 1) {
        super(rect.width, rect.height, false, 0xFF000000);
        grayScale = g;
        channel = c;
        if (grayScale) channel = 0;
        create(s);
    }

    public function create(s:uint):void {
        seed = s;
        if (seed == 0) seed = Math.floor(Math.random()*1000);
        lock();
        noise(seed, low, high, channel, grayScale);
        draw(this);
        unlock();
    }

}


import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "Arial";
    private var txtWidth:uint;
    private var fontSize:uint;

    public function Label(w:uint, s:uint) {
        txtWidth = w;
        fontSize = s;
        draw();
    }

    private function draw():void {
        txt = new TextField();
        txt.x = -uint(txtWidth/2);
        txt.width = txtWidth;
        addChild(txt);
        txt.autoSize = TextFieldAutoSize.CENTER;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = fontSize;
        tf.align = TextFormatAlign.CENTER;
        txt.defaultTextFormat = tf;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}