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

Parabola

Get Adobe Flash player
by J.J 24 Jan 2017
    Embed
/**
 * Copyright J.J ( http://wonderfl.net/user/J.J )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ylrI
 */

package  {

    

    import flash.display.MovieClip;

    import flash.events.Event;

    import flash.display.Graphics;

    import flash.geom.Point;

    import flash.events.MouseEvent;

    import flash.text.TextField;

    import flash.display.Sprite;

    import com.bit101.components.Label;

    import com.bit101.components.PushButton;

    import com.bit101.components.HSlider;

    import com.bit101.components.Component;

    import com.bit101.components.CheckBox;

    import flash.geom.ColorTransform;

    



    

    [SWF(backgroundColor=0xffffff, width=480, height=480, frameRate=60)]

    public class Parabola extends MovieClip {

        //taylor series



        public var g:Graphics;

        public var h:int;

        public var w:int;

        public var m:Point;

        public var mo:Point;

        public var cm:Point;

        public var sf:Number=6;

        

        public var O:Point;

        public var isDown:Boolean=false;

        public var ObjClicked:Boolean=false;

        public var Htxs:Vector.<Label>;

        public var Vtxs:Vector.<Label>;

        public var foci:Object;

        public var directx:Object

        public var clickables:Array=[];

        public var P:Number=0;

        public var q:Object

        public var A:Label

        public var B:Label

        public var C:Label

        public var AB:Label

        public var AC:Label

        public var animated:CheckBox;

        public var w2:Number;

        public function Parabola() {

            

            

            Htxs=new Vector.<Label>();

            Vtxs=new Vector.<Label>();

            g=this.graphics;

            h=stage.stageHeight;

            w=stage.stageWidth;

            m=new Point();

            mo=new Point();

            cm=new Point();

            O=new Point(w/2,h/2);

            w2=1;

            for(var i:int;i<6;i++){

                var tx:Label=new Label(this);

                

                tx.text="0";

                 

                

                tx.x=i*(w/6);

                tx.y=O.y;

                Htxs.push(tx);

                }

                

                for(i=0;i<6;i++){

                tx=new Label(this);

                tx.y=i*(w/6);

                tx.x=O.x;

                Vtxs.push(tx);

                }

                

                foci={x:0,y:-w/6,isClicked:false,update:null};

                directx={x:0,y:w/6,isClicked:false,update:null};

                q={x:100,y:0,isClicked:false,update:null};

                q.update=function (o:Object){

                    o.x=stage.mouseX-O.x;

                    }

                directx.update=foci.update=function (o:Object){

                    

                    o.y=stage.mouseY-O.y;

                

                    }

                clickables.push(foci);

                clickables.push(directx);

                clickables.push(q);

                

                var mc:Sprite=new Sprite();

                this.addChild(mc);

                    this.graphics.beginFill(0x101010);

                this.graphics.drawRect(0,0,w,h);

                g=mc.graphics;

                A=new Label(this,0,0,"A");

                B=new Label(this,0,0,"B");

                C=new Label(this,0,0,"C");

                    AB=new Label(this,0,0,"AB");

                AC=new Label(this,0,0,"AC");

                    var tf:ColorTransform=new ColorTransform();

                    

                    tf.color=0xffffff;

                    AC.transform.colorTransform=tf;

                    AB.transform.colorTransform=tf;

                animated=new CheckBox(this,10,10,"Animate");

                    animated.selected=true;

            stage.addEventListener(MouseEvent.MOUSE_DOWN,onMD);

            stage.addEventListener(MouseEvent.MOUSE_UP,onMU);

            

            

            this.addEventListener(Event.ENTER_FRAME,loop);

             

        }

        public function onZoomIn(e:MouseEvent){

            if(sf<0) sf+=.5;

                sf-=.5;

            

            }

            public function onZoomOut(e:MouseEvent){

            

                sf+=.5;

            

            }

        public function onMD(e:MouseEvent){

                isDown=true;

            m.setTo(stage.mouseX,stage.mouseY);

            

            }

        public function onMU(e:MouseEvent){

                isDown=false;

            ObjClicked=false;

            for each(var o:Object in clickables){o.isClicked=false;}

            O=O.add(mo);

            mo.setTo(0,0);

            }

        

    public function loop(e:Event):void{

        g.clear();

        

        if(isDown && ObjClicked==false){

            cm.setTo(stage.mouseX,stage.mouseY);

            mo.setTo(cm.x-m.x,cm.y-m.y);

            O=O.add(mo);

            g.moveTo(m.x,m.y);

            g.lineTo(cm.x,cm.y);

             

            }

        

        

        draw();

            for(var i:int;i<6;i++){

                var tx:Label=Htxs[i];

                tx.y=O.y;

                tx.y=Math.max(tx.y,0);

                tx.y=Math.min(tx.y,h-15)

            var xt:Number = (i / 6) *sf-(O.x/w)*sf;

                        tx.text=xt.toFixed(2)+"";

                var tx2:Label=Vtxs[i];

                tx2.x=O.x;

                tx2.x=Math.max(tx2.x,0)

                tx2.x=Math.min(tx2.x,w-15)

                xt = (i / 6) *sf-(O.y/h)*sf;

                xt*=-1;

            tx2.text=xt.toFixed(2)+"";

                        

            }

        

            

            drawParabola();

            O=O.subtract(mo);

            

            if(animated.selected==true){

                q.x+=w2;

                if(q.x<-w/2 || q.x>w/2) w2*=-1;

                

                }

    }

    public function X_2(q:Number){

        var pp:Number=(-P/(w/6));

        var dx:Number=directx.y/(w/6)

                return q*q/(2*pp)-dx+pp/2;

        }

    public function drawParabola(){

        drawFunc(X_2)

        

        g.endFill()

    

        

        for each(var pq:Object in clickables){

            g.lineStyle(0,0,0)

            

        g.beginFill(0xffffff,.5);

        g.drawCircle(O.x+pq.x,O.y+pq.y,5);

        }

        

        P=(foci.y-directx.y);

        //---------------------------------

        var a1=new Point(q.x,directx.y);

        

        g.drawCircle(a1.x+O.x,a1.y+O.y,5);

        g.endFill()

        g.lineStyle(1,0xffffff,.5);

        g.beginFill(0x11aaff,.1);

        g.moveTo(q.x+O.x,q.y+O.y)

        g.lineTo(a1.x+O.x,a1.y+O.y)

        g.lineTo(foci.x+O.x,foci.y+O.y);

        g.lineTo(q.x+O.x,q.y+O.y)

        A.x=q.x+O.x;

        A.y=q.y+O.y;

        B.x=a1.x+O.x;

        B.y=a1.y+O.y;

        C.x=foci.x+O.x-15;

        C.y=foci.y+O.y;

        

        

        if(isDown){

        for each(var o:Object in clickables){

            var m=new Point(o.x+O.x-stage.mouseX,o.y+O.y-stage.mouseY)

            var d:Number=m.x*m.x+m.y*m.y;

            if(o.isClicked==true && o.update!=null && animated.selected==false) o.update(o);

            if(d<25) {

                

                    

                if(ObjClicked==false){

                    ObjClicked=true;

                o.isClicked=true;

                    }

            

                }

            }

        }

        

        ///--------------

        var xt:Number = (q.x / w) *sf;

        var _y:Number = -X_2(xt) * (h / 2) / (sf / 2);

        q.y=_y;

        var fq=new Point(foci.x-q.x,foci.y-q.y)

        

        

        

        

        var l1=fq.x*fq.x+fq.y*fq.y;

        var aq=new Point(a1.x-q.x,a1.y-q.y);

        var l2=aq.x*aq.x+aq.y*aq.y;

        

        AC.x=-fq.x/2+foci.x+O.x;

        AC.y=-fq.y/2+foci.y+O.y;

        AB.x=-aq.x/2+a1.x+O.x;

        AB.y=-aq.y/2+a1.y+O.y;

        g.lineStyle(1,0xfffc00)

        g.moveTo(0,directx.y+O.y);

        g.lineTo(w,directx.y+O.y);

        

        AC.text="AC = "+(l1/(w/(6)*80)).toFixed(2);

        AB.text="AB = "+(l2/(w/(6)*80)).toFixed(2)

        }

        public function drawFunc(fx:Function) {

            g.endFill()

            g.lineStyle(2,0x00f6ff);

        g.moveTo(0,-fx((0 / w) *sf-(O.x/w)*sf)*(h/2)/(sf/2) + O.y);

        for (var i:int=1;i<w;i++) {

            

            var _x:Number = i;

            var xt:Number = (i / w) *sf-(O.x/w)*sf;

            var _y:Number = -fx(xt) * (h / 2) / (sf / 2) + O.y;

            g.lineTo(_x , _y);

        }

        g.endFill()

        

    }

    

    public function draw(){

    g.lineStyle(1,0xffffff);

        g.moveTo(0, O.y);

        g.lineTo(w, O.y);

        g.moveTo(O.x, 0);

        g.lineTo(O.x, h);



            

            

        }

    

    

    }

    

    

}