In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

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

astroid animation

Get Adobe Flash player
by Nos_lkSsvOhB 09 Aug 2013
/**
 * Copyright Nos_lkSsvOhB ( http://wonderfl.net/user/Nos_lkSsvOhB )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/uLnm
 */

package {
    import flash.display.*;
    import flash.events.*;
    public class astroid extends Sprite {
        private var xoffset:Number=465/2;
        private var yoffset:Number=465/2;
        private var a:Number=180;
        private var th:Number;
        private var bar:Array=new Array();

        private var th_inc:Number;         
        private var i:int;         
        private var thc:Number;         
        private var x_a:Number;         
        private var y_a:Number;         
        private var dydth:Number;         
        private var dxdth:Number;         

        public function astroid() {
            var line:Sprite=new Sprite();
            with(line){
                graphics.lineStyle(2,0x31C63F,1);
                graphics.moveTo(xoffset-a,yoffset);
                graphics.lineTo(xoffset+a,yoffset);
                graphics.moveTo(xoffset,yoffset-a);
                graphics.lineTo(xoffset,yoffset+a);
            }
            addChild(line);

            var bg:Sprite=new Sprite();
            with(bg.graphics){
                lineStyle(4,0x7A0707,1);
                th=0;
                moveTo(xoffset+3*a/4*Math.cos(th)+a/4*Math.cos(3*th),yoffset+3*a/4*Math.sin(th)-a/4*Math.sin(3*th));
                th+=Math.PI/60;
                for(;th<=2*Math.PI;th+=Math.PI/60){
                    lineTo(xoffset+3*a/4*Math.cos(th)+a/4*Math.cos(3*th),yoffset+3*a/4*Math.sin(th)-a/4*Math.sin(3*th));
                }
            }
            addChild(bg);
//            bg.x=-2*a;
//            bg.y=-2*a;

            for(i=0;i<4;i++){
                bar[i]=new Sprite();
                with(bar[i]){
                    graphics.lineStyle(10,0x0A091F,1,false,"none","none");
                    graphics.moveTo(0,-a/2);
                    graphics.lineTo(0,a/2);
                    _x=-2*a;
                    _y=-2*a;
                }
                addChild(bar[i]);
            }
            th=0;

            addEventListener(Event.ENTER_FRAME,onEnter);
        }

        private function onEnter(e:Event):void{   
            for(th_inc=0,i=0;th_inc<2*Math.PI;th_inc+=Math.PI/2,i++){
                thc=th+th_inc;
                x_a=a*Math.pow(Math.cos(thc),3);
                y_a=a*Math.pow(Math.sin(thc),3);
                dxdth=-3*a*Math.pow(Math.cos(thc),2)*Math.sin(thc);
                dydth=3*a*Math.pow(Math.sin(thc),2)*Math.cos(thc);
                bar[i].x=xoffset+(-y_a/(dydth/dxdth)+x_a)/2;
                bar[i].y=yoffset+(-dydth/dxdth*x_a+y_a)/2;
                bar[i].rotation=Math.atan2(dydth,dxdth)*180/Math.PI-90;
            }
            th+=Math.PI/60;
        }
    }
}