fc2ブログ

1/f ゆらぎ

2009-11-13 | 11:23

それぞれの円は1/f ゆらぎでアルファ値を変更しています。
1/f ゆらぎ参考





package{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.utils.*;
    import flash.filters.*;

    [SWF(width="800", height="300",backgroundColor="0x0")]

        public class f extends Sprite{
            private var balls:Array = [];
            private var timer:Timer = null;
            private var tick:Number = 0;
            private var colors:Array = [0xFF0000, 0xFFFF00, 0xFFFFFF];
            private var alphas:Array = [0, 0.5, 1];
            private var ratios:Array = [0, 192, 255];
            private var gradientGlowFilter:GradientGlowFilter = new GradientGlowFilter(0, 0, colors, alphas, ratios, 32, 32, 3, 3, "outer", false);

            public function f(){
                for(var i:int = 0 ; i < 50 ; i++){
                    var b:Ball = new Ball(0xffffff, 50*Math.random());
                    b.x = 800*Math.random();
                    b.y = 500*Math.random()
                    b.filters = [gradientGlowFilter];
                    addChild(b);
                    balls.push(b);
                }

                timer = new Timer(100);
                timer.addEventListener(TimerEvent.TIMER, cal);
                timer.start();

            }

            private function cal(e:Event) :void{
                for each(var ball:Ball in balls){
                    var x:Number = Math.PI*2*ball.tick - Math.PI;
                    var fx:Number = 0;
                    for(var i:Number = 0 ; i < 11 ; i++){
                        fx += Math.pow(2, -i)*Math.sin(Math.pow(2,i)*x);
                    }
                    fx = (fx+1.5)/3;
                    trace(fx);
                    ball.alpha = fx;
                    //gradientGlowFilter.blurX = 255*fx;
                    //gradientGlowFilter.blurY = 255*fx;
                    //gradientGlowFilter.strength = 255*fx;
                    ball.tickIncl();
                }
            }
        }
}

import flash.display.*;

internal class Ball extends Sprite{
    private var _tick:Number = Math.random();
    public function Ball(color:int, radius:int){
        graphics.beginFill(color);
        graphics.drawCircle(0,0,radius);
        graphics.endFill();
    }
    public function get tick():Number {
      return _tick;
    }
    public function set tick(tick:Number):void {
        _tick = tick;
    }
    public function tickIncl():void{
        _tick += 0.01;
        if(_tick > 1)
            _tick =  0;
    }


}

スポンサーサイト



Theme : プログラミング
Genre : コンピュータ

Comment

Post a comment

Secret