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-3-9

Get Adobe Flash player
by mutantleg 09 Mar 2015

    Talk

    hemingway at 09 Mar 2015 21:51
    Now, try adding velocity to the particles and solve the problem of over-stepping collisions
    mutantleg at 09 Mar 2015 23:08
    but that is how it was solved, by having a constant falling speed so i dont have to worry about velocity
    hemingway at 10 Mar 2015 00:00
    That's no fun :(
    hemingway at 10 Mar 2015 00:01
    http://wonderfl.net/c/hmat
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/nMPw
 */




package {
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.events.Event;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            pic = new BitmapData(64,64, false, 0);
            canvas = new BitmapData(64,64, false, 0);
            
            vecBlob = new Vector.<xBlob>(128, false); 
            var i:int; var num:int;     num = vecBlob.length;
            for (i = 0; i < num; i++)
            { vecBlob[i] = new xBlob(); }

            for(i =0; i < 64; i++)     { pic.setPixel(i, 55,0x808080); }
  
            for(i =0; i < 64; i++)     { pic.setPixel(0, i,0x808080); }
            for(i =0; i < 64; i++)     { pic.setPixel(55, i,0x808080); }
            
            for(i =0; i < 1024; i++)     { pic.setPixel(Math.random()*32, Math.random()*32+32,0x808080); }
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, onMdown);
            stage.addEventListener(MouseEvent.MOUSE_UP, onMup);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public function onMdown(e:MouseEvent):void { mdown = 1; }
        public function onMup(e:MouseEvent):void { mdown = 0; }        
        public var mdown:int = 0;
        
        public var pic:BitmapData;
        public var canvas:BitmapData;
        public var mat:Matrix = new Matrix();
        
        public var it:int = 0;
        public var vecBlob:Vector.<xBlob>;
        
        public function isWall(ax:int, ay:int):Boolean
        { return pic.getPixel(ax,ay) > 0;  }
        
        public function addBlob(ax:int, ay:int):void
        {
          var a:xBlob; var i:int; var num:int;
          num = vecBlob.length;
          for (i = 0; i < num; i++)
          {
            it += 1; if (it >= num) { it = 0 ;} 
            a = vecBlob[it]; if (a.active == false) 
            { a.active = true; a.cx = ax; a.cy= ay; it+=1; return; }
          }//nexti        
        }//addBlob
        
        public function onEnter(e:Event):void
        {
            var cw:Number; var ch:Number;            var mx:Number; var my:Number;
            var tx:int; var ty:int;            

            cw = ch = 8;
            mat.a = cw;        mat.d = ch;

            mx = stage.mouseX; my = stage.mouseY;
            tx = Math.floor(mx/cw);  ty = Math.floor(my/ch);
            
            
            canvas.unlock();
            canvas.lock();
            canvas.fillRect(canvas.rect, 0);
            canvas.draw(pic);
            
            if (mdown > 0) { addBlob(tx,ty);}
            
 
            var a:xBlob;
            var i:int; var num:int;     num = vecBlob.length;
            for (i = 0; i < num; i++)
            { 
              a = vecBlob[i];
              if (a.active == false) { continue; }
              if (isWall(a.cx, a.cy)) { a.active = false;  continue; }
              canvas.setPixel(a.cx,a.cy,0x404040);
             
              if (isWall(a.cx, a.cy+1) == false) 
              { a.cy += 1; if (a.cy >= 64) { a.active = false; }   continue; }
              
              if (isWall(a.cx-1, a.cy) == false)
              if (isWall(a.cx-1, a.cy+1) == false)   { a.cy+=1; a.cx-=1; continue;}
              
              if (isWall(a.cx+1, a.cy) == false)
              if (isWall(a.cx+1, a.cy+1) == false)   { a.cy+=1; a.cx+=1; continue;}
              
              a.active = false;
              pic.setPixel(a.cx,a.cy, 0x808080);
            }//nexti
            
            graphics.clear();
            graphics.beginBitmapFill(canvas, mat,false, false);
             graphics.drawRect(0,0,465,465);
            graphics.endFill();

            graphics.lineStyle(2, 0x00FF00,0.5);
            graphics.drawRect(tx*cw,ty*ch,cw,ch);
            
            
        }//onenter
        
        
    }//classend
}

internal class xBlob
{
  public var cx:int = 0;
  public var cy:int = 0;
  public var active:Boolean = false;
  
}//xblob