air_ball

by naokey0221
width = 500, height = 500,
frameRate=20,
♥0 | Line 207 | Modified 2010-06-25 22:12:24 | MIT License
play

ActionScript3 source code

/**
 * Copyright naokey0221 ( http://wonderfl.net/user/naokey0221 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/c0wE
 */

package
{
    import caurina.transitions.Tweener;
    import caurina.transitions.properties.ColorShortcuts;
    
    import flash.display.Sprite;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    
    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.media.Microphone;
    import flash.media.SoundMixer;
    import flash.media.SoundTransform;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.KeyboardEvent;
    import flash.geom.Matrix;
    import flash.ui.Keyboard;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import com.adobe.images.PNGEncoder;
    import com.adobe.images.JPGEncoder;
    
    
    
    
    
    
    [SWF(/*width = 500, height = 500,*/ /*frameRate=20,*/ backgroundColor=0xFFFFFF)]
    
    
    public class air_ball extends Sprite
    {
        private var _mic:Microphone;
        ColorShortcuts.init();
        private var frameCount:uint=0;//再生ヘッド(フレーム数カウント用の変数)
        private var frameCountLimit:uint=2;//コマ数(最終フレームの位置)
        
        
        public function air_ball()
        {
            // マイク準備
            _mic = Microphone.getMicrophone();
            _mic.setLoopBack(true);
            
            // ハウリング対策でボリュームを0にする
            var stf:SoundTransform = SoundMixer.soundTransform;
            stf.volume = 0;
            SoundMixer.soundTransform = stf;
            
            //ステージにクリック・イベントのハンドラを登録する
            //stage.addEventListener(MouseEvent.CLICK, onClick);
            
            
            //addEventListener(Event.ENTER_FRAME,onTime);
            addEventListener(Event.ENTER_FRAME, onMike);
            
            //池の描画
            var mycircle1:DrawCircle = new DrawCircle(200,200,80,0x3399ff);        
            var mycircles1:DrawCircles=new DrawCircles(200,200,10,10,0x666666,0);
            //addChild(mycircle1 );
            //addChild(mycircles1 );
            
            
            
        }
        
        
        private function onMike(e:Event):void 
        {
                // マイクが有効でなければ処理しない
                if (_mic.muted) return;
                
                var level:Number = _mic.activityLevel;
                
                // マイクのレベルが一定以上でなければ処理しない
                if (level < 10)
                { 
                    if(frameCount>0)
                    {
                        frameCount--;    
                        addcircle(frameCount);
                        
                    }
                    else if(frameCount<=0)
                    {
                        frameCount=0;
                        //addcircle(frameCount);
                                     
                    }
                    
                    return;
                }
                else if(level>=10)
                {
                    
                    frameCount++;
                    frameCount=addcircle(frameCount);
                    
                }                
            
            
            
            
        }     
        
        
        
        
        
        
        private function onTime(e:Event): void  
        {
            //半径をランダムでセット
            var nR:int =/*Math.ceil(Math.random()*1)+*/5;
            //色をランダムで選ぶ
            var color:int =0x0033FF; //Math.floor(Math.random()*0xffffff);  //
            
            //円のクラスのインスタンス作る
            var oneCircle:Sprite = new DrawCircle(0,0,nR,color);
            oneCircle.x= Math.round(Math.random()*400)+50;   //e.stageX;
            oneCircle.y= Math.round(Math.random()*400)+50;  //e.stageY;
            
            if(frameCount < frameCountLimit){
                addChild(oneCircle);
                changeColor(oneCircle,nR,0xFFFFFF);
                
            }else{
                
                frameCount=0;         
            }
            frameCount++;//再生ヘッドを進める
            
            
        }
        private function onClick(e:MouseEvent): void
        {
            //半径をランダムでセット
            var nR:int =/*Math.ceil(Math.random()*1)+*/1;
            //色をランダムで選ぶ
            var color:int =0xFF3366; //Math.floor(Math.random()*0xffffff);  //
            
            //円のクラスのインスタンス作る
            var oneCircle:Sprite = new DrawCircle(0,0,nR,color);
            oneCircle.x= Math.round(Math.random()*400)+50;   //e.stageX;
            oneCircle.y= Math.round(Math.random()*400)+50;  //e.stageY;
            
            addChild(oneCircle);
            changeColor(oneCircle,nR,0xFFFFFF);
            
        }
        
        
        private function changeColor(oneCircle:Sprite/*Sprite*/,nR:Number,color:int):void
        {
            
            Tweener.addTween(oneCircle,{
                //x: 50,//e.stageX,
                //y: 50,//e.stageY,
                scaleX: 1.2*nR,/*//Math.ceil(Math.random()*20)+5,*/
                scaleY: 1.2*nR,/*// Math.ceil(Math.random()*20)+5,*/
                _color:color,
                time:0.4/**Math.ceil(Math.random()*20)*/,
                delay:0,
                transition: "easeInOutSine",
                onComplete: changeColor,
                onCompleteParams: [oneCircle]});
        }
        private function changeColor2(oneCircle:Sprite,frameCount:uint,color:int):void
        {
            
            Tweener.addTween(oneCircle,{
                scaleX: 0,             /*//Math.ceil(Math.random()*20)+5,*/
                scaleY: 0,             /*// Math.ceil(Math.random()*20)+5,*/
                //_color:color,
                time:frameCount/80  /*Math.ceil(Math.random()*20)*/,
                delay:0,
                transition: "easeInOutSine",
                onComplete: changeColor,
                onCompleteParams: [oneCircle]});
        }
        
        private function addcircle(frameCount:uint):uint//void
        {
            
            //半径をランダムでセット
            var nR:int =/*Math.ceil(Math.random()*1)+*/3;
            //色をランダムで選ぶ
            var color:int =0xFF3366; /*Math.floor(Math.random()*0xffffff);*/  
            
            
            //円のクラスのインスタンス作る
            if(frameCount<10){
                color=0x0033FF;
            }
            else if(10<=frameCount&&frameCount<30){
                color=0xFF0000;
            }
            else if(30<=frameCount&&frameCount<60){
                color=0x00FF00;
            }
            else if(60<=frameCount&&frameCount<100){
                color=0x0000FF; 
            }
            else if(100<=frameCount&&frameCount<150){
                color=0xFFFF00; 
            }
            else if(150<=frameCount&&frameCount<210){
                color=0x00FFFF; 
            }
            else if(210<=frameCount&&frameCount<280){
                color=0xFF00FF; 
            }  
            else
            {
                color=0xFFFFFF;
                //return 0;
            }
            
            
            
            var oneCircle:Sprite = new DrawCircle(0,0,frameCount,color);
            oneCircle.x= 250;//Math.round(Math.random()*400)+50;   //e.stageX;
            oneCircle.y= 200;//Math.round(Math.random()*400)+50;  //e.stageY;
            
            addChild(oneCircle);
            changeColor2(oneCircle,frameCount-1, 0xFFFFFF);
          
            return frameCount;
        }
        
        
    }
}


import flash.display.Sprite/*Sprite*/;
import caurina.transitions.properties.ColorShortcuts;

class DrawCircle extends Sprite//MovieClip
{
    //ColorShortcuts.init();
    
    public function DrawCircle(centerX:int , centerY:int ,r:int,color:int)    
    {
        
        //alpha=1.0;
        //blendMode=BlendMode.HARDLIGHT;
        //線の太さを2,色をcolorにセットする
        graphics.beginFill(color,1.0);
        //graphics.lineStyle(0.7,color);
        //centerX,centerYを中心とする半径nRの円を描く
        graphics.drawCircle(centerX, centerY, r);
        graphics.endFill();
        
        
    }
}

class DrawCircles extends Sprite
{
    public function DrawCircles(centerX:Number,centerY:Number,r:Number,r2:Number,color:int,keisya:int)
    {
        
        for(var k:int =0 ;k<360 ;k+=14)
        {
            graphics.beginFill(color)
            graphics.moveTo(200+80*Math.cos(k*Math.PI/180),200+80*Math.sin(k*Math.PI/180));
            var x:Number= 200+80*Math.cos(k*Math.PI/180);
            var y:Number=200+80*Math.sin(k*Math.PI/180);
            for(var d:int =0 ;d<=360 ;d++)
            {
                var radian:Number =(d+keisya)*Math.PI/180;
                graphics.lineTo(
                    x+r*Math.cos(radian),
                    y+r2*Math.sin(radian))
            }
            graphics.endFill()
        }    
        
    }
}


class DrawCircleW extends Sprite
{
    public function DrawCircleW(centerX:Number,centerY:Number,r:Number,r2:Number,color:int,keisya:int)
    {
        
        
        //graphics.beginFill(color)
        graphics.lineStyle(2,0xffffff);
        graphics.moveTo(centerX+r,centerY);
        for(var d:int =0 ;d<360 ;d++)
        {
            var radian:Number =(d+keisya)*Math.PI/180;
            graphics.lineTo(
                centerX+r*Math.cos(radian),
                centerY+r2*Math.sin(radian))
        }
        //graphics.endFill()
    }
    
}