逆方向に回転する半球

by freddy
♥0 | Line 59 | Modified 2011-11-12 22:40:55 | MIT License
play

ActionScript3 source code

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

package {
    import flash.events.Event;
    import flash.display.Shape;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            // write as3 code here..
            
            var alpha:Number = 0;
            var line:Shape = new Shape();
            line.graphics.lineStyle(20, 0xFF0000);
            line.graphics.moveTo(-200, 0);
            line.graphics.lineTo(200, 0);
            
            function create(th:Number, r:Number, y:Number):Shape {
                var sh:Shape = new Shape();
                sh.graphics.beginFill(0x000000);
                sh.graphics.drawCircle(0, 0, 5);
                sh.y = y;
                sh.addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                    sh.x = r * Math.sin(th);
                    th += 0.1;
                    
                    sh.alpha = Math.cos(th) * y < 0 ? alpha : 1;
                });
                return sh;
            }
            
            var sp:Sprite = new Sprite();
            addChild(sp);
            sp.x = 240;
            sp.y = 240;
            var r:Number = 100;
            
            for (var i:int = 0; i < 100; i++) {
                var y:Number = Math.random() * 2 - 1;
                sp.addChild(create(Math.random() * 2 * Math.PI, r * Math.sqrt(1 - y * y), y * r));
            }
            sp.addChild(line);
            
            var count:int = 0;
            var mode:int = 0;
            addEventListener(Event.ENTER_FRAME, function(e:Event):void {
                count ++;
                if (mode == 1) {
                    alpha += 0.03;
                }

                if (count == 30 * 5) {
                    count = 0;
                    mode ++;
                    if (mode == 2) {
                        mode = 0;
                        sp.rotation += 90;
                    }


                    switch (mode) {
                    case 0:
                        alpha = 0;
                        break;
                    case 1:
                        //alpha = 1;
                        break;
                    }

                }

            });


        }
    }
}