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

flash on 2016-9-9

Get Adobe Flash player
by mutantleg 09 Sep 2016
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/Idaf
 */

package {
    import flash.text.TextField;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            deb = new TextField();
             deb.width=320; deb.height=240;
             deb.mouseEnabled=false;
            addChild(deb);
            
            skin = new BitmapData(16,16,false,0);
            skin.perlinNoise(3,2,5,5,true,true);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var vecFace:Vector.<int> = Vector.<int>([0,1,2, 2,1,3]);
        public var vecVert:Vector.<Number> = Vector.<Number>([0,0, 64,0, 0,64, 64,64]);
        public var vecUv:Vector.<Number> = Vector.<Number>([0,0, 1,0, 0,1, 1,1]);
        
        public var skin:BitmapData;
        
        public var deb:TextField;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
       
       
            
            var mx:Number; var my:Number;
            mx = stage.mouseX; my = stage.mouseY;
            var cw:Number; var ch:Number;
            cw= 128; ch=96;
            
            graphics.drawRect(mx,my, cw, ch);
            
            var rx:Number; var ry:Number;
            var rw:Number; var rh:Number;
            rx=96;ry=96;
            rw=160;rh=120;
            graphics.drawRect(rx,ry,rw,rh);
            
            var x0:Number; var y0:Number;
            var x1:Number; var y1:Number;

            var u0:Number; var v0:Number;
            var u1:Number; var v1:Number;

            var ut0:Number; var vt0:Number;
            var ut1:Number; var vt1:Number;
            
            u0=0;v0=0;
            u1=1;v1=1;
            
            ut0=0.3; vt0=0.3;
            ut1=0.7; vt1=0.7;
            
            x0=mx; y0=my;
            x1=x0+cw; y1=y0+ch;
           
            if (x0<rx){   x0=rx;  u0 = 1-( (x1-rx)/cw); }
            if (y0<ry) {y0=ry; v0 = 1 -((y1-ry)/ch) }
            if (x1>rx+rw) {x1=rx+rw; u1=((x1-x0)/cw); }
            if (y1>ry+rh) {y1=ry+rh; v1=((y1-y0)/ch); }
            if (x0>rx+rw ||y0>ry+rh||x1<rx||y1<ry){return;}
            
            u0 = ut0 + (ut1-ut0) * u0
            u1 = ut0 + (ut1-ut0) * u1
            v0 = vt0 + (vt1-vt0) * v0
            v1 = vt0 + (vt1-vt0) * v1
            
            graphics.lineStyle(2, 0xFF0000);
            graphics.drawRect(x0, y0, x1-x0, y1-y0);

                vecVert[0] = x0;     vecVert[1] = y0;
                vecVert[2] = x1;     vecVert[3] = y0;
                vecVert[4] = x0;     vecVert[5] = y1;
                vecVert[6] = x1;     vecVert[7] = y1;
                
                vecUv[0] = u0;      vecUv[1] = v0;
                vecUv[2] = u1;      vecUv[3] = v0;
                vecUv[4] = u0;      vecUv[5] = v1;
                vecUv[6] = u1;      vecUv[7] = v1;


                deb.text="u0 "+u0+"\nv0 "+v0+"\nu1 "+u1+"\nv1 "+v1+
                "\nut0 "+ut0+"\nvt0 "+vt0+"\nut1 "+ut1+"\nvt1 "+vt1;                
            
            graphics.beginBitmapFill(skin,null,false,false);
              graphics.drawTriangles(vecVert, vecFace, vecUv);
            graphics.endFill();
            
            
        }//onenter
        
        
    }//classend
}