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

Mountain Sound Visualization

Mountain Sound Visualization

Made By Cheon Seong-hyeok

Blog : http://blog.shipnk.com/
/**
 * Copyright CheonSH ( http://wonderfl.net/user/CheonSH )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5eUW
 */

package {
    import flash.display.Sprite;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import flash.media.Sound;
    import flash.display.Shape;
    import flash.media.SoundMixer;
    import flash.display.StageAlign;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.geom.ColorTransform;
    import flash.media.SoundChannel;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.events.ProgressEvent;
    import flash.geom.Rectangle;
    import flash.system.Security;
    
    public class FlashTest extends Sprite {

        const num:int = 256;
        
        private var i:int;
        private var snd:Sound = new Sound;
        private var shape:Shape = new Shape();
        private var ba:ByteArray = new ByteArray;
        private var power:Number;
        private var values:Array = [];
        private var bd:BitmapData = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0 );
        private var b:Bitmap = new Bitmap( bd );
        private var color:ColorTransform = new ColorTransform( 0.99, 1,1,0.995 );
        private var sc:SoundChannel = new SoundChannel();
        private var tf:TextField = new TextField();

        public function FlashTest() {
            // write as3 code here..
            stage.align = StageAlign.TOP_LEFT;
            tf.textColor = 0xFFFFFF;
            tf.text = 'Test';
            tf.mouseEnabled  = false;
            tf.autoSize = TextFieldAutoSize.LEFT;
            for( i = 0; i < num; ++ i )
            {
                values[ i ] = 0;
            }
            Security.loadPolicyFile( 'http://www.shipnk.com/crossdomain.xml' );
            snd.load( new URLRequest( 'http://www.shipnk.com/sound/LetMeHitIt.mp3' ) );
            snd.addEventListener(Event.COMPLETE, completeEvent );
            snd.addEventListener(ProgressEvent.PROGRESS, progressEvent );
            addChild( b );
            addChild( shape );
            addChild( tf );
            stage.addEventListener(Event.ENTER_FRAME, process );
        }
        
        private function progressEvent ( e:ProgressEvent ) :void
        {
            tf.text = 'Loading... ' + int((e.bytesLoaded/e.bytesTotal*100)*100)/100 + '%';
        }
        
        private function completeEvent ( e:Event ) :void
        {
            sc = snd.play( 0, 999999 );
            tf.text = '제작 : 천성혁 - http://blog.shipnk.com/';
        }

        private function process ( e:Event ):void
        {
            SoundMixer.computeSpectrum(ba, true);
            //
            shape.graphics.clear();
            shape.graphics.beginFill( 0xFF00FF, 1 );
            shape.graphics.lineStyle( 2, 0xEE22EE );
            shape.graphics.moveTo( stage.stageWidth, stage.stageHeight );
            shape.graphics.lineTo( 0, stage.stageHeight );
            for( i = 0; i < num; ++ i )
            {
                power = ba.readFloat();
                if( values[ i ] < power )
                {
                    values[ i ] = power;
                }
                else
                {
                    values[ i ] *= 0.95;
                    power = values[ i ];
                }
                shape.graphics.lineTo( i * stage.stageWidth / num, stage.stageHeight - stage.stageHeight*0.8 * power );
            }
            shape.graphics.lineTo( stage.stageWidth, stage.stageHeight );
            //
            power = sc.leftPeak + sc.rightPeak;
            power /= 2;
            for( i = 0; i < power * 3; ++ i )
            {
                bd.colorTransform( bd.rect, color );
                bd.scroll( 1, -1 );
                bd.fillRect( new Rectangle( 0,0,1,bd.height ), 0x884488 );
                bd.draw( shape );
            }
        }
    }
}