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

forked from: Area of a Triangle(三角形の面積)

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

// forked from shohei909's Area of a Triangle(三角形の面積)
package {
    import flash.filters.GlowFilter;
    import flash.geom.Rectangle;
    import com.bit101.components.*;
    import flash.events.Event;
    import flash.display.*;
    public class FlashTest extends Sprite {
        public var text:InputText;
        public var text2:InputText;
        public var i_num:int=3;
        public var dots:Array = [];
        public var r:Rectangle = new Rectangle( 10, 10, 445, 420 );
        public var canvas:Sprite = new Sprite();
        public var target:Object;
        
        public function FlashTest() {
            addChild( new Bitmap( new BitmapData(465,465,false,0x111111) ) )
            addChild( canvas );
            text = new InputText( this, 5, 440 );
            
            text.setSize( 455, 20 );
            
            
            for( var i:int = 0; i<i_num; i++ ){
                var dot:Dot = new Dot();
                var dotposition_x:Number=r.x;
                dot.move( int( r.x + r.width* Math.random() ), int( r.y + r.height*Math.random() ),i );
                dot.addEventListener( "mouseDown", start );
                dot.addEventListener( "mouseUp", stop );
                stage.addEventListener( "mouseMove", move );
                dot.buttonMode = true;
                canvas.addChild( dot );
                dots.push( dot );
                
            }
            update();
        }
        
        private function update():void{
            var g:Graphics = canvas.graphics;
            g.clear();
            g.lineStyle( 1, 0x66CC66, 1);
            g.beginFill( 0xFFFFFF, 0.1 );
            var d:Dot = dots[i_num-1];
            g.moveTo( d.x, d.y );
            for( var i:int = 0; i < i_num; i++ ){
                d = dots[i];
                g.lineTo( d.x, d.y );
            }
            text.text = "Area = " + GeomUtil.triangleSum( dots[0].x, dots[0].y, dots[1].x, dots[1].y, dots[2].x, dots[2].y ).toFixed(1)+"--"; 
        }
        
        private function start(e:Event):void{ 
            target = e.target;        
        }
        private function move(e:Event):void{ 
            if( target ){
                target.move( mouseX, mouseY );
                update();
            }          
        }
        
        private function stop(e:Event):void{
            target = null;
        }
    }
}

import flash.events.Event;
import flash.geom.Point;
import flash.display.Graphics;
import flash.display.Sprite;
import com.bit101.components.*;

class Dot extends Sprite{
    private var lbl:Label;
    private var lbl2:Label;
    function Dot(){
        var g:Graphics = graphics;
        var dot_i:int;
        g.beginFill( 0x00FF00, 2 );
        g.drawRect( -5, -5, 10, 10 );
        Style.LABEL_TEXT = 0xff6666;
        lbl = new Label( this, 0, 0, "" )
        lbl2 = new Label( this, 0, 20, "" )
        move(x,y,dot_i);
    }
    public function move(x:Number,y:Number,i:int):void{
        this.x = x; this.y = y; lbl.text = "(" + x + "," + y + ")";
       // lbl2.text = "point= "+i;
    }
}

class GeomUtil{
    static public function triangleSum( ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number ):Number{
        var s:Number = 0.5 * ((cy-ay)*(bx-ax)-(cx-ax)*(by-ay)) 
        return s>0?s:-s;
    }
}