Dead Code Preservation :: Archived AS3 works from wonderfl.net

Homage to Isaac Newton

Sir Isaac Newton, 1642 - 1727.
For those who aren't afraid to stand on the shoulders of giants.
Get Adobe Flash player
by GreekFellows 06 Aug 2012
/**
 * Copyright GreekFellows ( http://wonderfl.net/user/GreekFellows )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jjp8
 */

package {
    import flash.events.Event;
    import flash.text.TextFormat;
    import flash.text.TextField;
    import flash.display.Sprite;
    
    public class Swiper extends Sprite {
        public var messages:Array = ["If I have", "seen further", "it is by", "standing", "on the shoulders", "of giants.", "Isaac Newton"];
        public var ci:int = 0;
        
        public var sprite:Sprite;
        
        public const WIPE_UPWARDS:String = "wipe upwards";
        public const WIPE_DOWNWARDS:String = "wipe downwards";
        public const WIPE_LEFTWARDS:String = "wipe leftwards";
        public const WIPE_RIGHTWARDS:String = "wipe rightwards";
        
        public var animations:Array = [];
        
        public function Swiper() {
            sprite = new Sprite();
            
            text(messages[ci]);
        }
        
        public function prepare():void {
            animations = [WIPE_UPWARDS, WIPE_DOWNWARDS, WIPE_LEFTWARDS, WIPE_RIGHTWARDS];
            
            sprite.graphics.beginFill(Math.random() * 0xffffff, 1);
            sprite.graphics.drawRect(0, 0, 465, 465);
            sprite.graphics.endFill();
            
            var at:String = animations[Math.floor(Math.random() * animations.length)];
            
            switch (at) {
                case WIPE_UPWARDS:
                sprite.y = 465;
                
                case WIPE_DOWNWARDS:
                sprite.y = -465;
                
                case WIPE_LEFTWARDS:
                sprite.x = -465;
                
                case WIPE_RIGHTWARDS:
                sprite.x = 465;
            }
            
            this.addChild(sprite);
            
            this.addEventListener(Event.ENTER_FRAME, animate);
        }
        
        public function animate(e:Event):void {
            sprite.x -= sprite.x / 10;
            sprite.y -= sprite.y / 10;
            
            if (Math.abs(sprite.x) < 1 && Math.abs(sprite.y) < 1) {
                sprite.x = 0;
                sprite.y = 0;
                
                if (this.numChildren >= 2) {
                    this.removeChildAt(0);
                }
                
                sprite = new Sprite();
                
                ci += 1;
                
                if (ci > messages.length - 1) {
                    ci = 0;
                }
                
                text(messages[ci]);
            }
        }

        
        public function text(str:String):TextField {
            var tf:TextField = new TextField();
            tf.text = str;
            tf.selectable = false;
            
            var fmt:TextFormat = new TextFormat();
            fmt.font = "Segoe UI Light";
            fmt.size = 48;
            fmt.align = "center";
            fmt.color = 0xffffff;
            
            tf.setTextFormat(fmt);
            tf.width = tf.textWidth + 4;
            tf.height = tf.textHeight + 4;
            tf.x = 465 / 2 - tf.width / 2;
            tf.y = 465 / 2 - tf.height / 2;
            
            sprite.addChild(tf);
            
            prepare();
            
            return tf;
        }
    }
}