flash on 2009-4-21

by awef
♥0 | Line 55 | Modified 2009-04-21 18:06:08 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.Sprite;
    
    [SWF(backgroundColor="#FFFFFF", frameRate="60")]
    
    public class main extends Sprite
    {
        public function main()
        {
            var tmp : bug;
            for(var i : uint = 0; i < 25; i++)
            {
                tmp = new bug();
                stage.addChild(tmp);
                tmp.tween(0, 0);
            }
        }
    }
}

import flash.display.Sprite;
import caurina.transitions.Tweener;

class bug extends Sprite
{
    function bug()
    {
        var s : uint = 16;
        
        graphics.beginFill(0);
        graphics.drawRect(-s / 2, -s / 2, s, s);
        graphics.endFill();
        
        graphics.lineStyle(s / 10, 0xFFFF00);
        
        graphics.moveTo(-s / 4, -s / 4);
        graphics.lineTo(-s / 4, -s / 2);
        
        graphics.moveTo(s / 4, -s / 4);
        graphics.lineTo(s / 4, -s / 2);
    }
    
    public function tween(arg_x : int, arg_y : int) : void
    {
        Tweener.addTween(this,
        {
            rotationZ : -Math.atan2(x - arg_x, y - arg_y) / Math.PI * 180,
            transition : "linear",
            time : 1,
            onComplete : (function() : void
            {
                Tweener.addTween(this,
                {
                    x : arg_x,
                    y : arg_y,
                    transition : "linear",
                    time : Math.sqrt(Math.pow(x - arg_x, 2) + Math.pow(y - arg_y, 2)) / 50,
                    onComplete : (function() : void {tween(Math.random() * stage.stageWidth, Math.random() * stage.stageHeight);})
                });
            })
        });
        
    }
}