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

FF: Sound Spectrum

音注意!!
murakenさんエフェクト使用
camera of undefined
http://wonderfl.kayac.com/code/e30a7c4c5755fc45417a01d38f889774d3c640b3
Get Adobe Flash player
by WLAD 29 Dec 2015
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/0HBq
 */

// forked from sadamitsu's Sound Spectrum
//音注意!!
//murakenさんエフェクト使用
//camera of undefined
//http://wonderfl.kayac.com/code/e30a7c4c5755fc45417a01d38f889774d3c640b3
   
package{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.DisplayObject;
    import flash.display.GradientType;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.Event;
    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;
    
    [SWF( backgroundColor='#000000',frameRate=60,quality='low')]
    public class Main extends Sprite {
        //
        private var snd:Sound = new Sound();
        private var channel:SoundChannel;
        private var ba:ByteArray = new ByteArray();
        private var array:Array;
        private var numCount:Number = 0;
        private var a:Number = 0;
        private var rate:Number = .90;
        private var currentRotation:Number = 500;
        private var rotationInc:Number = .05;
        private var mc:MovieClip
        private var lowSound:MovieClip
        private var middleSound:MovieClip
        private var highSound:MovieClip
        //
        private var bmp:Bitmap;
        private const BMD_WIDTH:int = stage.stageWidth;
        private const BMD_HEIGHT:int = stage.stageHeight;
        private var baseColor:uint = 0x000000;
        private var baseBmd:BitmapData;
        private var editBmd:BitmapData;
        private var noiseBmd:BitmapData;
        private var sandstormBmd:BitmapData;
        private var sorce:DisplayObject;
        private var baseMatrix:Matrix;
        private var pointArray:Array;
        private var randArray1:Array;
        private var randArray2:Array;
        private var randNum1:Number;
        private var bmdUpNum:Number;
        private var _bmp:Bitmap;

        public function Main() {
            mc=new MovieClip()
            addChild(mc)
            
            lowSound=new MovieClip()
            mc.addChild(lowSound)
            lowSound.x=stage.stageWidth/2
            lowSound.y = stage.stageHeight / 2
            
            middleSound=new MovieClip()
            mc.addChild(middleSound)
            middleSound.x=stage.stageWidth/2
            middleSound.y = stage.stageHeight / 2
            
            highSound=new MovieClip()
            mc.addChild(highSound)
            highSound.x=stage.stageWidth/2
            highSound.y=stage.stageHeight/2
            

            Security.loadPolicyFile("http://mutast.heteml.jp/crossdomain.xml");
            snd.load(new URLRequest("http://mutast.heteml.jp/works/music/music.mp3"));
            channel = snd.play();
            this.addEventListener(Event.ENTER_FRAME, spectrum);
            NoiseDisplay()
        }
 
        private function spectrum(event:Event):void {
            if(++numCount%2 == 0) {
                a = 0;
                lowSound.graphics.clear();
                middleSound.graphics.clear();
                highSound.graphics.clear();
                SoundMixer.computeSpectrum(ba,true,0);
                currentRotation += rotationInc;
                var radians:Number = 0;
                if(currentRotation == 0) {
                    currentRotation = Math.random();
                }
                radians = currentRotation * Math.PI * 2;
            
                //低音域付近
                var numM:int=3
                for(var i:Number = 0; i < 100; i+=numM) {
                    var sizeNum:Number=10
                    a = ba.readFloat();
                    var numX:Number = a*200;
                    var numY:Number = -a*stage.stageHeight;
                    lowSound.graphics.beginFill(0x0299FD|((a*500)*5 << 8),.75);
                    var radiusRotate:Number = 0;
                    var pointX:Number = (stage.stageWidth/3 * Math.cos(360/numM + (i/(100/numM))/numM * Math.PI * 2))+stage.stageWidth/2;
                    var pointY:Number = (stage.stageWidth/3 * Math.sin(360/numM + (i/(100/numM))/numM* Math.PI * 2))+stage.stageHeight/2;
                    lowSound.graphics.drawCircle(pointX-stage.stageWidth/2,pointY-stage.stageHeight/2,numX);
                    lowSound.scaleX=lowSound.scaleY=a*2
                }
                //中音域付近
                numM=2
                for(i = 100; i < 156; i+=numM) {
                    sizeNum=10
                    a = ba.readFloat();
                    numX = a*200;
                    numY = -a*stage.stageHeight;
                    middleSound.graphics.beginFill(Math.random()*0xFF0000|((a*500)*5 << 8),.75);
                    radiusRotate = 0;
                    pointX = (stage.stageWidth/3 * Math.cos(360/numM + (i/(56/numM))/numM * Math.PI * 2))+stage.stageWidth/2;
                    pointY = (stage.stageWidth/3 * Math.sin(360/numM + (i/(56/numM))/numM* Math.PI * 2))+stage.stageHeight/2;
                    middleSound.graphics.drawCircle(pointX-stage.stageWidth/2,pointY-stage.stageHeight/2,numX*2);
                    middleSound.scaleX=middleSound.scaleY=a*3
                }
                //高音域付近
                numM=3
                for(i = 156; i < 256; i+=numM) {
                     sizeNum=10
                    a = ba.readFloat();
                    numX = a*400;
                    numY = -a*stage.stageHeight;
                    highSound.graphics.beginFill(0xFF0000|((a*500)*5 << 8),.75);
                    radiusRotate = 0;
                    pointX = (stage.stageWidth/3 * Math.cos(360/numM + (i/(100/numM))/numM * Math.PI * 2))+stage.stageWidth/2;
                    pointY = (stage.stageWidth/3 * Math.sin(360/numM + (i/(100/numM))/numM* Math.PI * 2))+stage.stageHeight/2;
                    highSound.graphics.drawCircle(pointX-stage.stageWidth/2,pointY-stage.stageHeight/2,numX*2);
                    highSound.scaleX=highSound.scaleY=a*1
                }
        
            }
        }
        private function NoiseDisplay():void {
            sorce = mc;
            bmp = new Bitmap();
            addChild(bmp);
            baseBmd = new BitmapData(BMD_WIDTH, BMD_HEIGHT, false, baseColor);
            editBmd = baseBmd.clone();
            noiseBmd = baseBmd.clone();
            sandstormBmd = baseBmd.clone();
            baseMatrix = new Matrix();
            pointArray = new Array(new Point(0, 0), new Point(0, 0), new Point(0, 0));
            randArray1 = new Array(Math.random() + 1, Math.random() + 1, Math.random() + 1);
            randArray2 = new Array(0, 0, 0);
            randNum1 =0.5;
            bmdUpNum = 0;
            bmp.bitmapData = noiseBmd;
            bmp.smoothing = true;
            bmp.visible = false;
            addEventListener(Event.ENTER_FRAME, upDate);
            bmp.visible = true;
            sorce.visible = false;
        }
        private function _onResize(e:Event):void {
            var W:Number = stage.stageWidth;
            var H:Number = stage.stageHeight;
            baseMatrix = new Matrix();
            baseMatrix.scale(BMD_WIDTH/W, BMD_HEIGHT/H);
            bmp.scaleX = W/BMD_WIDTH;
            bmp.scaleY = H/BMD_HEIGHT;
            bmp.x = 0;
            bmp.y = 0;
        }
        private var _keyCnt:Number = 0;
        private function upDate(e:Event):void {
            var copy_bmd:BitmapData = baseBmd.clone();
            copy_bmd.draw(sorce, baseMatrix);
            editBmd = copy_bmd.clone();
            
            for (var i:int = 0; i < 3; i++) {
                if (randArray1[i] >= 1){
                    --randArray1[i];
                    randArray2[i] = Math.random() / 4 + 0.03;
                } 
                randArray1[i] = randArray1[i] + randArray2[i];
                _keyCnt += (48-_keyCnt) / 4;
                pointArray[i].x = Math.ceil(Math.sin(randArray1[i] * Math.PI * 2) * randArray2[i] * _keyCnt*2);
                pointArray[i].y = 0;
            }
            
            var keyNum:Number = 1*(Math.abs(pointArray[0].x) + Math.abs(pointArray[1].x) + Math.abs(pointArray[2].x) + 8) / 4;

            i = BMD_HEIGHT;
            while (i--){
                var offset:Number = Math.sin(i / BMD_HEIGHT * (Math.random() / 8 + 1) * 1.3 * Math.PI * 2)* 1.3 * keyNum * keyNum;
                editBmd.copyPixels(copy_bmd, new Rectangle(offset, i, BMD_WIDTH - offset, 1), new Point(0, i));
            }
            sandstormBmd.noise(int(Math.random() * 1000), 0, 255, 7, false);
            var sandNum:Number = 10;
            editBmd.merge(sandstormBmd, editBmd.rect, new Point(0,0), sandNum, sandNum, sandNum, 0);
            noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[0], BitmapDataChannel.RED, BitmapDataChannel.RED);
            noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[1], BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
            noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[2], BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);
        }
    }
}