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

Sound Star

こっそりとSoundMixer.computeSpectrumの第二引数を
stageクリックでかえれるようにしてみた。
trueとfalseでの動きの違いを確かめる。
/**
 * Copyright yd_niku ( http://wonderfl.net/user/yd_niku )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/exDI
 */

// forked from gaina's soundtest6
//こっそりとSoundMixer.computeSpectrumの第二引数を
//stageクリックでかえれるようにしてみた。
//trueとfalseでの動きの違いを確かめる。

package  
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.*;
    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 flash.filters.BlurFilter;
    import frocessing.display.F5MovieClip2DBmp;
    import frocessing.color.*;
    [SWF(width=465,height=465,backgroundColor=0x0)]
    public class soundSpectrum extends F5MovieClip2DBmp
    {
        private var _particles:Vector.<Star>;
        private var snd:Sound;
        private var FFTswitch:Boolean = false;
        private var $color:ColorHSV = new ColorHSV();
        //private var fil:Array = [];
        public function setup():void{
            size( 465, 465 );
            //背景の描画
            background( 0 );
            //HSV
            colorMode( HSV, 1 );
                
            stage.addEventListener(MouseEvent.CLICK, FFTswitcher);
            
            Wonderfl.capture_delay( 15 );
            
            _particles = new Vector.<Star>();
            playSound("http://www.takasumi-nagai.com/soundfiles/sound001.mp3");
        }
        
        private var _angleY:Number = 0;
        private var _angleC:Number = 0;
        public function draw():void{
            _angleY+=6;
            _angleC++;
          
            $color.hsv(_angleC%360,1,0.2+(_angleC%240)/240*0.8)
            beginFill($color.value,0.9); 
            drawRect(0,0,465,465);
            endFill();
            
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes, FFTswitch, 0);
            var i:uint, j:uint;
            
            var lev:Number = 0;
            const DEF_CNT:Number = 36;
            var cnt:Number = DEF_CNT;
            var aX:Number  = Math.cos(_angleY/180*Math.PI);
            var aY:Number  = Math.sin(_angleY/180*Math.PI);
            for (i = 0; i < 2; i++)
            {
                for (j = 0; j < 256; j++)
                {
                    var rf:Number = bytes.readFloat();
                    
                    if (cnt-->0) lev += rf;
                    else {
                        if( lev > 2 ) {
                            var r:Number = random(lev,0.2);
                            var p:Star = new Star();
                            p.x = 232;
                            p.y = 232;
                            p.vx = lev/3+aX*r;
                            p.vy = Math.random()*lev/6+aY*r/2;
                            p.mass = lev/5;
                            _particles.push(p);
                        }
                        cnt = DEF_CNT; lev = 0;
                    }
                }
            }
            
            //for each( var s:Star in _particles ){
            for(var k:int=_particles.length-1; k>=0; k-- ){
                var s:Star = _particles[k];
                if(s.life<=0) {
                    _particles.splice(i,1);
                    continue;
                }
                s.x += s.vx;
                s.y += s.vy + Math.sin((s.life%360)/180*Math.PI)+0.5;
                s.life--;
                
                stroke(0,0,1,(s.life-80)/80);
                drawCircle( s.x, s.y, 3*s.mass*Math.random() );
                
                var offset:Number = random(Math.PI);
                
                noStroke();
                beginFill(0xFFFFFF,(s.life-80)/80);
                var sradius:Number = random(6,0.1)*s.mass, ssradius:Number, partAngle:Number = Math.PI*2/10;
                
                var ssx:Number, ssy:Number;
                for(var t:int=0; t<10;++t){
                    ssradius = (t%2==0?0.35:1)*sradius;
                    ssx = s.x+Math.sin(partAngle*t+offset)*ssradius;
                    ssy = s.y+Math.cos(partAngle*t+offset)*ssradius;
                    if(t==0) moveTo( ssx, ssy );
                    lineTo( ssx, ssy ); 
                }
                endFill();
            }
        }
    
        private function playSound(sndUrl:String):void
        {
            snd = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10,true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.load(req, context);
            var sndChannel:SoundChannel=new SoundChannel();
            sndChannel = snd.play(0, 5);
            
        }
        
        private function FFTswitcher(e:MouseEvent):void 
        {
            if (FFTswitch) { FFTswitch = false; } else { FFTswitch = true;}
        }
            
    }
}
class Star{
    public var x:Number = 0;
    public var y:Number = 0;
    public var vx:Number = 0;
    public var vy:Number = 0;
    public var life:Number = 240;
    public var mass:Number = 1;
}