flash on 2009-4-21 awef forked:0favorite:0lines:55license : MIT License modified : 2009-04-21 18:06:08 Embed Tweet 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);}) }); }) }); } } Code Fullscreen Preview Fullscreen Math.pow rotationZ Tweener.addTween time Math.atan2 Math.sqrt addChild Math.PI Math.random uint Sprite int