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 2015-8-30

Get Adobe Flash player
by mutantleg 29 Aug 2015
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/hUEg
 */

package {
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {

            stage.quality = "LOW";
          
            skin = new BitmapData(64,64, false, 0);
            //skin.perlinNoise(16,8, 32, 16, true,true, 7);
            skin.noise(23);
            
            var i:int; var k:int; var nw:int; var nh:int;
            nw = skin.width; nh = skin.height;
            for (i=0;i<nh;i+=1) 
            { for (k=0;k<nw;k+=1)
              {
                  skin.setPixel(k,i, (k&i)<<16 | (k&i)<<8 | (k|i));
              }//nextk    
            }//nexti
            
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
           
       //    drawBox2(0,0,0, 256,16,256);

/*
            graphics.lineStyle();
            graphics.beginBitmapFill(skin,null, false, true);            
             drawTri(0,0,0,  256, 0, 0,  0,0,256, true,  0,0, 1,0, 0,1);   
             drawTri(0,0,256,  256, 0, 0,  256,0,256, true, 0,1, 1,0, 1,1);   
            graphics.endFill();
 */           

            var mx:Number; var my:Number;
            mx = stage.mouseX; my = stage.mouseY;
        //    drawPlane(mx-8,my-8, mx+8,my+8, 0, skin);
            
            var ax:Number; var ay:Number;
            ay = (2*my - (mx-rendw)) * 0.5;
            ax = (mx-rendw) + ay ;
            ax += camx; ay+= camy;  

            graphics.lineStyle();            
            var i:int; var k:int; var nw:int; var nh:int; 
            var wy:Number; wy =0;
            nw = 8; nh = 8;
            for (i=0;i<nh;i+=1) 
            { for (k=0;k<nw;k+=1)
              {
                 wy=8;
                if (  (k*64 > ax || i*64 > ay || k*64+64 < ax || i*64+64 < ay) == false) { wy=32; }  
                drawPlane(k*64,i*64, k*64+64,i*64+64, wy, skin);
              }//nextk    
            }//nexti
            
           // drawPlane(0,0, 256,256, 8, skin);
           // drawPlane(0,0, 64,64, 16, skin);
            
            drawPlane(ax-8,ay-8, ax+8,ay+8, 0, skin);
            
        }//onenter


        public var skin:BitmapData;            
            
        public function drawPlane(x0:Number, z0:Number, x1:Number, z1:Number, y:Number, tx:BitmapData=null):void
        {
          if (tx!=null) { graphics.beginBitmapFill(tx, null, false, true);   }
          drawTri(x0,y,z0,  x1, y, z0,  x0,y,z1, false,  0,0, 1,0, 0,1);   
          drawTri(x0,y,z1,  x1, y, z0,  x1,y,z1, false, 0,1, 1,0, 1,1);               
          if (tx !=null) { graphics.endFill(); }          
        }//drawplane    
      
            
        public var camx:Number = 0;        public var camy:Number = 0;        public var camz:Number = 0; 
        public var rendw:Number = 465 * 0.5;        public var rendh:Number = 465 * 0.5; 
        public function drawLine(ax:Number, ay:Number, az:Number,
        bx:Number, by:Number, bz:Number):void
        {
           var sx:Number; var sy:Number;     
           ax -= camx; ay -= camy; az -= camz;
           bx -= camx; by -= camy; bz -= camz;
            sx = ax - az + rendw;     sy = (ax * 0.5) + (az * 0.5) - ay;
            graphics.moveTo(sx,sy);
            sx = bx - bz + rendw;     sy = (bx * 0.5) + (bz * 0.5) - by;
            graphics.lineTo(sx, sy);
        }//drawline 
        
         public function drawBox2(ax:Number, ay:Number, az:Number,
           aw:Number, ah:Number, ad:Number):void
        {   drawBox(ax,ay,az,ax+aw,ay+ah,az+ad); }
        
       public function drawBox(ax:Number, ay:Number, az:Number,
          bx:Number, by:Number, bz:Number):void
        {
          drawLine(ax, ay, az,   bx, ay, az);
          drawLine(ax, by, az,   bx, by, az);
          drawLine(ax, ay, bz,   bx, ay, bz);
          drawLine(ax, by, bz,   bx, by, bz);
          
          drawLine(ax, ay, az,   ax, by, az);
          drawLine(bx, ay, az,   bx, by, az);
          drawLine(ax, ay, bz,   ax, by, bz);
          drawLine(bx, ay, bz,   bx, by, bz);
          
          drawLine(ax, ay, az,   ax, ay, bz);
          drawLine(bx, ay, az,   bx, ay, bz);
          drawLine(ax, by, az,   ax, by, bz);
          drawLine(bx, by, az,   bx, by, bz);
        }//drawbox          
          
        public var tempVert:Vector.<Number> = new Vector.<Number>(6, false);
        public var tempUv:Vector.<Number> = new Vector.<Number>(6, false);
        public var tempInd:Vector.<int> = Vector.<int>([0, 1, 2]);  

         public function drawTri(x0:Number, y0:Number, z0:Number,
          x1:Number, y1:Number, z1:Number, x2:Number, y2:Number, z2:Number, cull:Boolean = false,
          u0:Number=0, v0:Number=0, u1:Number=1, v1:Number=0, u2:Number=0, v2:Number=1):void
          {
            var mat:Vector.<Number>;    var tv:Vector.<Number>;    var tt:Vector.<Number>;
            var sx0:Number, sy0:Number;  var sx1:Number, sy1:Number; var sx2:Number, sy2:Number;     
 
            x0 -= camx; y0 -= camy; z0 -= camz;
            x1 -= camx; y1 -= camy; z1 -= camz;
            x2 -= camx; y2 -= camy; z2 -= camz;
            
           sx0 = x0 - z0 + rendw;     sy0 = (x0 * 0.5) + (z0 * 0.5) - y0;
           sx1 = x1 - z1 + rendw;     sy1 = (x1 * 0.5) + (z1 * 0.5) - y1;
           sx2 = x2 - z2 + rendw;     sy2 = (x2 * 0.5) + (z2 * 0.5) - y2;
        
            if (cull) { if (((sx1 - sx0) * (sy2 - sy0) - (sx2 - sx0) * (sy1 - sy0)) < 0) { return; } }

            tv = tempVert;   tt = tempUv;
            tv[0] = sx0; tv[1] = sy0;   tv[2] = sx1; tv[3] = sy1;   tv[4] = sx2; tv[5] = sy2;
            tt[0] = u0; tt[1] = v0;    tt[2] = u1; tt[3] = v1;  tt[4] = u2; tt[5] = v2;
            
            graphics.drawTriangles(tv, tempInd, tt);
          }//drawtri
        
        
        
    }//classend
}