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

forked from: forked from: Matrix code "movie"

First sharing code from Alexandre Delattre / Grafyweb.com
MUSIC/visualizer FROM: http://wonderfl.net/c/5ddY
/**
 * Copyright xor ( http://wonderfl.net/user/xor )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/kcJY
 */

// forked from Merci's forked from: Matrix code "movie"
// forked from mookymook49's Matrix code "movie"
//First sharing code from Alexandre Delattre / Grafyweb.com


// MUSIC/visualizer FROM: http://wonderfl.net/c/5ddY

package {
    import flash.display.*;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Rectangle;
    import flash.geom.Transform;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFieldType;
    import flash.text.AntiAliasType;
    import flash.text.TextFormat;
    import flash.events.Event;
    import flash.text.TextFormatAlign;
    import flash.filters.GlowFilter;

    
        import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.filters.BitmapFilter;
    import flash.filters.BlurFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.utils.ByteArray;
    import flash.media.SoundLoaderContext;
    
    
    [SWF(frameRate = "30", width="465", height="465",backgroundColor="0xcccccc")]
    public class Matrixcode extends Sprite {
      
        private static const POLICY_FILE:String = " http://hycro.crz.jp/crossdomain.xml";
        private static const SOUND_FILE:String = "http://hycro.crz.jp/wonderfl/sound/u-chi-u.mp3";
        
        // 1
        // http://hycro.crz.jp/crossdomain.xml
        // http://hycro.crz.jp/crossdomain.xmlhttp://hycro.crz.jp/wonderfl/sound/u-chi-u.mp3
        
        // 2
        // http://mutast.heteml.jp/crossdomain.xml
        // http://mutast.heteml.jp/works/music/music.mp3
        
        // 3 
        // http://www.ventoline.com/crossdomain.xml
        // http://www.ventoline.com/music2.mp3  
                    
        private var _sound:Sound = new Sound();
        private var _channel:SoundChannel;
        
        private var _leftBars:Vector.<Bar>;
        private var _rightBars:Vector.<Bar>;
        
        private var _canvas:Bitmap;
        private var _colorTransform:ColorTransform = new ColorTransform(.9, .9, .9);
        private var _filter:BitmapFilter = new BlurFilter(8, 4);
        
        
        private var _maxLabel:int = 150;
            
            private var _maxWidth:int = 50;
            
            private var vecText:Vector.<lettre> = new Vector.<lettre>();
            
            private var colorT:ColorTransform;
            
            private var canvas:BitmapData;
            
            private var contLabel:Sprite = new Sprite();
            
            

        
        public function Matrixcode() 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        private function init(e:Event = null):void {
            this.removeEventListener(Event.ADDED_TO_STAGE, init);
            
            
            
              _leftBars = new Vector.<Bar>();
            _rightBars = new Vector.<Bar>();
            var bar:Bar;
            for (var i:uint=0; i<64; i++) {
                // ?
                bar = new Bar(0xffffff, false);
                bar.y = i * (Bar.LENGTH + Bar.MARGIN) + Bar.LENGTH + 10; // ????????? Bar.LENGTH ????
                bar.x = (Bar.LENGTH + Bar.MARGIN) * Bar.NUM_RECT;
                _leftBars.unshift(bar);
                
                // ?
                bar = new Bar(0xffffff, false);
                bar.y = i * (Bar.LENGTH + Bar.MARGIN) + 10;
                bar.x = Math.floor(stage.stageWidth / 2) + 1;
                _rightBars.unshift(bar);
            }
            
            // ???Bitmap???
            _canvas = new Bitmap(new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xff000000));
            addChild(_canvas);
            
             Security.loadPolicyFile(POLICY_FILE);
            
            // ????????
            _sound.addEventListener(Event.COMPLETE, onLoadComplete);
            _sound.addEventListener(IOErrorEvent.IO_ERROR, onLoadError);
            _sound.load(new URLRequest(SOUND_FILE), new SoundLoaderContext(10000, true));
            
            _canvas.x =465;
            _canvas.rotation =90;
            _canvas.blendMode="overlay";
            
            var bg_canvas:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xff000000);
            var bg_color:Bitmap = new Bitmap(bg_canvas);
            this.addChild(bg_color);
            
              
            canvas = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0x00000000);
            
           // var glow:GlowFilter = new GlowFilter(0x00ff00, 1, 8, 8, 2, 1, false, false);
           // this.contLabel.filters = [glow];
            this.addChild(this.contLabel);
            
            var fd:Bitmap = new Bitmap(canvas);
            var blur:BlurFilter = new BlurFilter(2, 2, 1);
            fd.filters = [blur];
            this.addChild(fd);            
         
           // colorT = new ColorTransform(Math.random()*0.95+1, Math.random()*1,Math.random()*1+0.95, 0.98, 0, 0, 0, -0.2);
             addChild(_canvas);
             
           // this.addEventListener(Event.ENTER_FRAME, refresh);
            
        }
        
        private function refresh(e:Event):void {
                 colorT = new ColorTransform(Math.random()*1+0.55, Math.random()*1+0.55,Math.random()*1+0.65, Math.random()*1+0.45, 0, 0, 0, Math.random()*1+0.45);
                canvas.colorTransform(new Rectangle(0, 0, stage.stageWidth, stage.stageHeight), this.colorT);
            
            for (var i:int = 0; i < this.vecText.length; i++) {
                this.refreshLabel(i);
                
           
                
            }
            
            if (this.vecText.length < this._maxLabel) {
                var label:lettre = new lettre();
                label.x = int(Math.random()*this._maxWidth)*(stage.stageWidth/this._maxWidth);        
                this.contLabel.addChild(label);
                this.vecText.push(label);
            }
            
        }
         private function onLoadComplete(evt:Event):void {
            this.addEventListener(Event.ENTER_FRAME, loop);
            _channel = _sound.play(0, int.MAX_VALUE);
        }
        
        
    
        private function loop(evt:Event):void {
            
            refresh(null)
            
            var data:ByteArray = new ByteArray();
            var matrix:Matrix;
            var rect:Rectangle = new Rectangle(0, 0, _canvas.width, _canvas.height);
            var dp:Point = new Point(0, 0);
            
            _canvas.bitmapData.lock();
            
            // ?????????
            SoundMixer.computeSpectrum(data, true);
            
            // ???
            var d:Number = Math.max(_channel.rightPeak, _channel.leftPeak) * .02;
            _colorTransform.redMultiplier += (.5 - Math.random()) * d;
            _colorTransform.blueMultiplier += (.5 - Math.random()) * d;
            _colorTransform.greenMultiplier += (.5 - Math.random()) * d;
            _colorTransform.redMultiplier = Math.min(Math.max(_colorTransform.redMultiplier, .8), 1);
            _colorTransform.blueMultiplier = Math.min(Math.max(_colorTransform.blueMultiplier, .8), 1);
            _colorTransform.greenMultiplier = Math.min(Math.max(_colorTransform.greenMultiplier, .8), 1);
            _canvas.bitmapData.colorTransform(rect, _colorTransform);
            
            // ????????
            _canvas.bitmapData.applyFilter(_canvas.bitmapData, rect, dp, _filter);
            
            // ?????????
            for (var i:uint=0; i<64; i++) {
                _leftBars[i].setLevel(Math.sqrt((data.readFloat() + data.readFloat() + data.readFloat() + data.readFloat()) / 4));
                matrix = new Matrix();
                matrix.rotate(Math.PI)
                matrix.translate(_leftBars[i].x, _leftBars[i].y);
                _canvas.bitmapData.draw(_leftBars[i], matrix);
            }
                
            // ?????????
            for (i=0; i<64; i++) {
                _rightBars[i].setLevel(Math.sqrt((data.readFloat() + data.readFloat() + data.readFloat() + data.readFloat()) / 4));
                matrix = new Matrix();
                matrix.translate(_rightBars[i].x, _rightBars[i].y);
                _canvas.bitmapData.draw(_rightBars[i], matrix);
            }
            
            _canvas.bitmapData.unlock();
        }
        
        /**
         * ?????
         * 
         * @private
         */
        private function onLoadError(evt:IOErrorEvent):void {
            trace("??????????");
        }
        private function refreshLabel(i:int):void {
                    
            
            var label:lettre = this.vecText[i];
            
            if (label.y > stage.stageHeight) {
                this.contLabel.removeChild(label);
                this.vecText.splice(i, 1);
            }else{            
            label.refresh();
            }
            
            if ((label.y - label.lastPrint) > label.textHeight) {
                label.lastPrint = label.y;
                this.printLabel(label);
                
            }
            
        }
        
        private function printLabel(label:lettre):void {
            var trans:Transform = label.transform;
            
            this.canvas.draw(label,trans.matrix);
            
        }
        

        
    }
    
    }
    
    import flash.filters.GlowFilter;
    import flash.text.TextField;
    import flash.text.TextFormat;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormatAlign;
    import flash.text.AntiAliasType;
    /**
     * ...
     * @author grafyweb
     */
     
     
    class lettre extends TextField
    {
        //[Embed(source = "../matrix code nfi.ttf", fontFamily = "foo", embedAsCFF = 'false')]            
         //   public static const FONT_Matrix:String;
            
            private var allowT:Array;
            
            private var vitesse:Number;
            
            public var lastPrint:int = -30;
        
        public function lettre()
        {
            var str:String = new String("abcdefghijklmnopqrstuvwxyz0123456789");             
            
            allowT = str.split("");
            this.creaLabel();
            this.vitesse = 1+Math.random() * 2;
            
        }
        
        public function refresh():void {
                    
            this.text = allowT[int(Math.random() * (allowT.length - 1))];
            this.y += this.vitesse;
      format1.size = Math.random()*5+5;
             format1.color = Math.random()*0xFFFFFF;
            this.defaultTextFormat = format1; 
            
        }
       private var format1:TextFormat = new TextFormat();
        private function creaLabel():void {
            

          
            format1.font = "Arial";
            format1.color = 0xcccccc;
            format1.size = 10;
            format1.leading = -4;
            format1.bold = true;
            

            
            //this.embedFonts = true;
            this.width = 15;    
            this.multiline = true;
            this.wordWrap = true;                
            this.autoSize = TextFieldAutoSize.NONE;
            this.antiAliasType = AntiAliasType.ADVANCED;
            this.defaultTextFormat = format1;
            this.text = allowT[int(Math.random()*(allowT.length-1))];
            this.defaultTextFormat = format1;            
        }
        
    }
    

        
  
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;

class Bar extends Sprite {
    // 四角の数
    public static const NUM_RECT:uint = 33;
    // 四角の大きさ
    public static const LENGTH:uint = 5;
    // マージン
    public static const MARGIN:uint = 2;
    // 最大時の長さ
    public static const MAX_LENGTH:uint = (LENGTH + MARGIN) * NUM_RECT - MARGIN;
    
    // Bar を構成する四角形
    private var _rects:Vector.<Bitmap>;
    
    /**
     * コンストラクタ
     */
    public function Bar(color:uint=0xffffff, gradient:Boolean=false) {
        var r:uint = (color & 0x00ff0000) >> 16;
        var g:uint = (color & 0x0000ff00) >> 8;
        var b:uint = (color & 0x000000ff);
        
        _rects = new Vector.<Bitmap>;
        for (var i:uint = 0; i < NUM_RECT; i++) {
            var grad:Number = Math.min(Math.sqrt((i+1)/NUM_RECT+.4), 1)
            var c:uint = (r*grad << 16) | (g*grad << 8) | b*grad;
            var bmp:Bitmap = new Bitmap(new BitmapData(LENGTH, LENGTH, false, gradient ? c : color));
            
            bmp.x = i * (LENGTH + MARGIN);
            _rects[i] = bmp;
            addChild(bmp);
            bmp.visible = false;
        }
    }
    
    /**
     * レベルを設定
     * 
     * @param level 0〜1の範囲の実数値
     */
    public function setLevel(level:Number):void {
        level = Math.min(NUM_RECT, Math.floor(NUM_RECT * level));
        
        for (var i:uint = 0; i<NUM_RECT; i++) {
            _rects[i].visible = i<level;
        }
    }
}