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

TailSoundVisualizer2

音にあわせて左右に揺れながら伸びるSoundvsualizer
少しでも模様が描かれているみたいに見えるようにと少し、変更してみました。

*曲を3曲選べるようにしました。
*スライドバーを6個追加
[Color] 色の調整
[Fade] 描かれる線の消える速度の調整
[Alpha] 線のalphaの値の調整
[Round] 線の角度の調整
[Thickness] 線の太さの調整
[Length] 線の長さの調整
/**
 * Copyright yabuchany ( http://wonderfl.net/user/yabuchany )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/4vFa
 */

package {
    import com.bit101.components.*;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Shape;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.display.BlendMode;
    import flash.filters.*;
    import flash.geom.Point;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.net.URLRequest;
    import flash.utils.ByteArray;
    import frocessing.display.*;
    
     /*
     * Free Music Archive: Digi G'Alessio - ekiti son feat valeska - april deegee rmx 
     * http://creativecommons.org/licenses/by-nc-nd/3.0/
     */    
    
    /*
    * Free Music Archive:Lee_Rosevere_-_01_-_Christmas_Eve_At_Midnight_Small_Town_Square
    * http://creativecommons.org/licenses/by-nc-nd/3.0/
    */
    
    [SWF(width = "465", height = "465", backgroundColor = "0x000000", frameRate = "60")]
    public class TailSounds12 extends F5MovieClip2DBmp {
        private var inc:Number = 0;
        private var s:Sound = new Sound();
        private var sc:SoundChannel;
        private var ba:ByteArray = new ByteArray();
        private var array:Array;
        private var a:Number = 0;
        private var t:Number = 0;
        private var bm:Bitmap;
        private var _bmd:BitmapData;
        private var _cnt:int = 0;
        private var _thinkness:Number = 0;
        private var _alpha:Number = 20;
        private var _fade:Number = 1;
        private var _length:int = 10;
        private var _color:int = 100;
        private var _r:Number = 2500;
        
        private var hs1:HSlider;
        private var hs2:HSlider;
        private var hs3:HSlider;
        private var hs4:HSlider;
        private var hs5:HSlider;
        private var hs6:HSlider;
        
        private var context:SoundLoaderContext;
        private var req:URLRequest;
        private var playflag:Boolean = false;
        
        public function TailSounds12() {
            super();
        }
        public function setup():void {
            
            _bmd = new BitmapData(465, 430, true, 0);
            bm = new Bitmap(_bmd);
            addChild(bm);
            colorMode(HSB, 100);
            smooth();
            background(0);
            // ラジオボタン
            new Label(this, 0, 205, "[Chose Music]");
            new RadioButton(this, 10, 225, "Music1", true, onRadioClick);            
            new RadioButton(this, 10, 240, "Music2", false, onRadioClick);            
            new RadioButton(this, 10, 255, "Music3", false, onRadioClick);            
            
            
            // スライドバー
            new Label(this, stage.stageWidth/2+50+4,395, "[Round]");
            hs6 = new HSlider(this, stage.stageWidth/2+50+4+10+50,400);
            hs6.maximum = 50000;
            hs6.minimum = 2500;
            hs6.value = _r;
            hs6.addEventListener(Event.CHANGE, function(e:Event):void { _r = hs6.value; });            
            
            
            new Label(this, stage.stageWidth/2+50+4,420, "[Thickness]");
            hs1 = new HSlider(this, stage.stageWidth/2+50+4+10+50,425);
            hs1.maximum = 100;
            hs1.minimum = 0.1;
            hs1.value = _thinkness;
            hs1.addEventListener(Event.CHANGE, function(e:Event):void { _thinkness = hs1.value; });
            
            
            new Label(this, 4, 445, "[Alpha]");
            hs2 = new HSlider(this, 50,450);
            hs2.maximum = 100;
            hs2.minimum = 20;
            hs2.value = _alpha;
            hs2.addEventListener(Event.CHANGE, function(e:Event):void { _alpha = hs2.value; } );
            
            new Label(this, 4, 420, "[Fade]");
            hs3 = new HSlider(this, 50,425);
            hs3.maximum = 100;
            //hs3.minimum = 8;
            hs3.minimum = 1;
            hs3.value = _fade;
            hs3.addEventListener(Event.CHANGE, function(e:Event):void { _fade = hs3.value; } );
            
            new Label(this, stage.stageWidth/2+50+4+4, 445,  "[Length]");
            hs4 = new HSlider(this, stage.stageWidth/2+50+4+10+50,450);
            hs4.maximum = 150;
            hs4.minimum = 10;
            hs4.value = _length;
            hs4.addEventListener(Event.CHANGE, function(e:Event):void { _length = hs4.value; } );
            
            new Label(this, 4, 395,  "[Color]");
            hs5 = new HSlider(this, 50,400);
            hs5.maximum = 150;
            hs5.minimum = 10;
            hs5.value = _length;
            hs5.addEventListener(Event.CHANGE, function(e:Event):void { _color = hs5.value; } );
            
            
            
            context = new SoundLoaderContext(1, true);
            req= new URLRequest("http://www.yabuchany.com/blog/wp-content/uploads/2010/12/src/koinu.mp3");
            s.load(req,context);
            s.addEventListener(Event.COMPLETE, loadCompleteHandler);
            
        }
        
        private function onRadioClick(e:Event): void {
            var radio:RadioButton = e.currentTarget as RadioButton;
            switch(radio.label) {
                 case "Music1":
                    
                    s = new Sound();
                    context = new SoundLoaderContext(1, true);
                    req = new URLRequest("http://www.yabuchany.com/blog/wp-content/uploads/2010/12/src/koinu.mp3");
                    s.load(req,context);
                    s.addEventListener(Event.COMPLETE, loadCompleteHandler);
                    if (playflag == true) {
                        sc.stop();
                    }
                    break;
                case "Music2":
                    
                    s = new Sound();
                    context = new SoundLoaderContext(1, true);
                    req = new URLRequest("http://yabuchany.com/blog/wp-content/uploads/2010/12/src/Lee_Rosevere_-_01_-_Christmas_Eve_At_Midnight_Small_Town_Square.mp3");
                    s.load(req,context);
                    s.addEventListener(Event.COMPLETE, loadCompleteHandler);
                    if (playflag == true) {
                        sc.stop();
                    }
                    break;
                    
                case "Music3":
                    s = new Sound();
                    context = new SoundLoaderContext(1, true);
                    req = new URLRequest("http://level0.kayac.com/images/murai/Digi_GAlessio_-_08_-_ekiti_son_feat_valeska_-_april_deegee_rmx.mp3");
                    s.load(req,context);
                    s.addEventListener(Event.COMPLETE, loadCompleteHandler);
                    if (playflag == true) {
                        sc.stop();
                    }
                    break;
            }
        }
        public function loadCompleteHandler(e:Event):void {
            new PushButton(this, stage.stageWidth / 2 - 60, 440, "Play", playmusic);
        }
        public function soundCompleteHandler(e:Event):void
        {
            new PushButton(this, stage.stageWidth/2-60, 440, "Play", playmusic);
            sc.stop();
            background(0);
            _cnt = 0;    
        }
        public function playmusic(e:MouseEvent):void{
            sc = s.play(0, 0);
            sc.addEventListener(Event.SOUND_COMPLETE,soundCompleteHandler);
            playflag = true;
            _cnt = 0;
            new PushButton(this, stage.stageWidth / 2 - 60, 440, "Stop", playstop);
            
        }
        public function playstop(e:MouseEvent):void {
            new PushButton(this, stage.stageWidth/2-60, 440, "Play", playmusic);
            sc.stop();
            background(0);
            _cnt = 0;
        }        
        public function draw():void {
            _cnt = _cnt + 1;
            trace("_cnt"+_cnt);
            SoundMixer.computeSpectrum(ba, true, 0);
            a = 0;
            //background(0);
            noStroke();
            rectMode(CORNER);
            //fill(0, 8);
            fill(0, _fade);
            rect(0, 0, 465, 465);
            for (var i:int = 0; i < 512; i = i + 8) {
                
                var c:int;
                for (c = 0; c < 100; c++) {
                    //stroke(random(100), 60, 100, _alpha);
                    stroke(random(_color), 60, 100, _alpha);
                }
                
                
                inc +=0.0001+i/500000;
                var angle:Number = sin(inc) / 40.0 + sin(inc * 1.2) /30;    
                if (a > 1) {
                    a = ba.readFloat();
                    //a = 30;
                }
                for (var j:int = 0; j < 1; j++) {
                    a = ba.readFloat();
                }
                
                //var num:int = 150;                
                var num:int = _length;                
                var w:int = stage.stageWidth / 2;
                var r:Number = 0.00001;
                //var r2:Number = i / 2000;
                //var r2:Number = i / 50000;
                //var r2:Number = i / 2500;
                var r2:Number = i / _r;
                
                if (_cnt < 100) {
                    tail2(i, stage.stageHeight, a * num, angle + 0.00001 + r2);
                    tail2(i, stage.stageHeight, a * num, -(angle + 0.00001 + r2));
                    tail(i, 0, a * num, angle + 0.00001 + r2);
                    tail(i, 0, a * num, -(angle + 0.00001 + r2));
                }else if(_cnt<200){
                    tail2(w, stage.stageHeight-i, a * num, angle + 0.00001 + r2);
                    tail2(w, stage.stageHeight - i, a * num, -(angle + 0.00001 + r2));
                    tail(w, 0 + i, a * num * 2, angle + 0.00001 + r2);
                    tail(w, 0+i, a * num * 2, -(angle + 0.00001 + r2));
                }else if (_cnt < 300) {
                    tail(i, 0, a * num, angle + 0.00001 + r2);
                    tail(i, 0, a * num, -(angle + 0.00001 + r2));
                }else if (_cnt < 400) {
                    tail2(i, stage.stageHeight, a * num, angle + 0.00001 + r2);
                    tail2(i, stage.stageHeight, a * num, -(angle + 0.00001 + r2));
                }else if (_cnt < 500) {
                    tail2(w, stage.stageHeight-i, a * num, angle + 0.00001 + r2);
                    tail2(w, stage.stageHeight - i, a * num, -(angle + 0.00001 + r2));
                }else if (_cnt < 600) {
                    tail(w, 0 + i, a * num * 2, angle + 0.00001 + r2);
                    tail(w, 0+i, a * num * 2, -(angle + 0.00001 + r2));
                }
                if (_cnt >= 600) {
                    _cnt = 0;
                }
                
                bm.blendMode = BlendMode.ADD;
            }
        }    
        public function tail(x:int,y:int,units:int,angle:Number):void {
            pushMatrix();
            translate(x, y);
            //var n:int =a*10;
             //var n:int = a*30;
             var n:int = a*_thinkness;
            for(var i:int=units;i>0;i--){
                strokeWeight(n-i);
                line(0, 0, 0, 8);
                translate(0, 8);
                rotate(angle);
            }
            popMatrix();
        }
        public function tail2(x:int,y:int,units:int,angle:Number):void {
            pushMatrix();
            translate(x, y);
            //var n:int = a*50;
            //var n:int = a*30;
            var n:int = a*_thinkness;
            for(var i:int=units;i>0;i--){
                strokeWeight(n-i);
                line(0, 0, 0, -8);
                translate(0, -8);
                rotate(angle);
            }
            popMatrix();
        }        
    }
}