fizzbuzz

by seino
♥0 | Line 39 | Modified 2010-05-31 23:53:07 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    [SWF(width="400", height="400", backgroundColor="#DDDDDD", frameRate="50")] 
    public class fizzbuzz extends Sprite {
      private var cnt:int = 0;
      private var timer:Timer;
        public function fizzbuzz() {
        	   var tf:TextField = new TextField();
        	   tf.x = stage.stageWidth /2;
        	   tf.y = stage.stageHeight /2;
        	   stage.addChild(tf);
        	   
           timer = new Timer(500);
           timer.addEventListener("timer", function():void{
           	
                                            cnt++;
           	                               //fizzbuzz
                                            tf.text = (cnt%3?'':'fizz')+(cnt%5?cnt%3?cnt:'':'buzz');
           	                               tf.autoSize = TextFieldAutoSize.LEFT;
           	                               tfEffect(tf);
                                            if(cnt == 100){
                                               timer.removeEventListener("timer", arguments.callee);
                                               timer.stop();
                                            }
                                           });
           timer.start();
        }
        
        private function tfEffect(tf:TextField):void{
        	   tf.defaultTextFormat = new TextFormat("",
        	                                         70 * Math.random()+10, //ある程度のフォントサイズ確保
        	                                         0xFFFFFF * Math.random() + 0x0000CC,//ある程度の濃さ確保
        	                                         Math.floor(Math.random())); //True/Falseをランダム指定
        	   tf.x = stage.stageWidth * Math.random();
        	   tf.y = stage.stageHeight * Math.random();
        	}
    }
}

Forked