forked from: flash on 2013-11-4

by mutantleg forked from flash on 2013-11-4 (diff: 14)
♥0 | Line 60 | Modified 2013-11-08 04:27:32 | MIT License
play

ActionScript3 source code

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

// forked from mutantleg's flash on 2013-11-4
package {
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
      
        public function FlashTest()
        {
            
            var myTri:xTri;
            
            myTri = new xTri();
            myTri.a.setValue(230,50);
            myTri.b.setValue(50,40);
            myTri.c.setValue(80,220);
            
            drawTri(myTri);
            
            var tempa:xVert  = new xVert;
            var tempb:xVert = new xVert;
            var tempc:xVert = new xVert;
/*            
            tempa.cx = myTri.a.cx +(myTri.b.cx - myTri.a.cx) *0.5;
            tempa.cy = myTri.a.cy +(myTri.b.cy - myTri.a.cy) *0.5;
            graphics.drawCircle(tempa.cx, tempa.cy, 4);
            
            tempb.cx = myTri.b.cx +(myTri.c.cx - myTri.b.cx) *0.5;
            tempb.cy = myTri.b.cy +(myTri.c.cy - myTri.b.cy) *0.5;
            graphics.drawCircle(tempb.cx, tempb.cy, 4);
            
            tempc.cx = myTri.c.cx +(myTri.a.cx - myTri.c.cx) *0.5;
            tempc.cy = myTri.c.cy +(myTri.a.cy - myTri.c.cy) *0.5;
            graphics.drawCircle(tempc.cx, tempc.cy, 4);
 */           
            var t1:xTri = new xTri();
            var t2:xTri = new xTri();
            var t3:xTri = new xTri();
            var t4:xTri = new xTri();
            
            var origa:xVert = myTri.a;
            var origb:xVert = myTri.b;
            var origc:xVert = myTri.c;
            
  /*          
            t1.copyVerts(tempa,tempb,tempc);  drawTri(t1, 0.4);
            t2.copyVerts(origa,tempa,tempc);  drawTri(t2, 0.6);
            t3.copyVerts(tempa,origb,tempb);  drawTri(t3, 0.4);
            t4.copyVerts(tempb,origc,tempc);  drawTri(t4, 0.4);
   */
            tempa.cx = (myTri.a.cx + myTri.b.cx + myTri.c.cx) *0.333;
            tempa.cy = (myTri.a.cy + myTri.b.cy + myTri.c.cy) *0.333;
            graphics.drawCircle(tempa.cx, tempa.cy, 4);
            
            t1.copyVerts(tempa,origa,origb);  drawTri(t1, 0.4);
            t2.copyVerts(tempa,origb,origc);  drawTri(t2, 0.4);
            t3.copyVerts(tempa,origc,origa);  drawTri(t3, 0.4);
            
            
            
        }//ctor
        
        
        
        
        public function drawTri(t:xTri, aa:Number=0.5):void
        {
            var c:uint;
            var w:Number;
            w = (t.b.cx - t.a.cx) * (t.c.cy - t.a.cy) - (t.c.cx - t.a.cx) * (t.b.cy - t.a.cy);
            if (w > 0) { c = 0xFF0000; } //backface
            else { c = 0x0000FF;}
            
            graphics.lineStyle(2,0,0.5);
            graphics.beginFill(c, aa);
             graphics.moveTo(t.a.cx, t.a.cy);
             graphics.lineTo(t.b.cx, t.b.cy);
             graphics.lineTo(t.c.cx, t.c.cy);
             graphics.lineTo(t.a.cx, t.a.cy);
             
            graphics.endFill();
        }//drawtri
        
        
    }//classend
}

internal class xVert
{
 public var cx:Number = 0;
 public var cy:Number = 0;   
 public function setValue(x:Number, y:Number):void { cx =x; cy= y;}
 public function copyVert(a:xVert):void { cx = a.cx; cy= a.cy;}
}

internal class xTri
{
 public var a:xVert = new xVert();
 public var b:xVert = new xVert();
 public var c:xVert = new xVert();   
 
 public function copyVerts(ca:xVert, cb:xVert, cc:xVert):void
 { a.copyVert(ca); b.copyVert(cb); c.copyVert(cc);  } 
 
}