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: forked from: forked from: flash on 2009-5-26

Get Adobe Flash player
by set0 09 Jun 2009
/**
 * Copyright set0 ( http://wonderfl.net/user/set0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/l79a
 */

// forked from set0's flash on 2009-5-26
package 
{
  import flash.display.*;
  import flash.events.*;
  import flash.net.*;
  import flash.system.*;
  import flash.geom.*;
  import flash.text.*;
  import flash.filters.*;
  import flash.utils.*;
  import org.libspark.betweenas3.*;
  
  [SWF(width=465, height=465, frameRate=60, backgroundColor=0xffffff)]
  public class FlashTest extends Sprite {
      
      private var image_width:Number = 0;
      private var image_height:Number = 0;
      private var image_x:Number = 0;
      private var image_y:Number = 0;
      private var pixel_max:int = 0;
      private var pixel_n:int = 0;
      private var image_array:Array = [];
      
      
      private var buffer:BitmapData = new BitmapData(465, 465, false);
      private var screen:Bitmap = new Bitmap(buffer);

      
      public function FlashTest()
      {
          var image_url:String = "http://farm2.static.flickr.com/1271/1168949483_4b0523cc19_m.jpg";
          
          var loader:Loader = new Loader();
          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoadComplete);
          loader.load(new URLRequest(image_url), new LoaderContext(true));
          
      }
      
      private function onImageLoadComplete(e:Event):void
      {
         var loader:Loader = LoaderInfo(e.target).loader;
         var base:BitmapData = Bitmap(loader.content).bitmapData;
         var bmp:Bitmap = loader.content as Bitmap
         var pixel_x:uint = 0;
         var pixel_y:uint = 0;
         var d:int = 0;
         
         image_width = loader.width;
         image_height = loader.height;
         image_x = stage.stageWidth / 2 - image_width / 2;
         image_y = stage.stageHeight / 2 - image_height / 2;
         
         var count:uint = 0;
         
         for(var img_y:int=0;img_y<image_height;img_y++) {
             for(var img_x:int=0;img_x<image_width;img_x++) {
                 image_array[count] = new Pixel(base.getPixel(img_x, img_y), img_x, img_y);
                 count++;
             }
         }
         
         pixel_max = image_array.length;
         
         image_array.sortOn("color", Array.NUMERIC);
         
         addChild(screen);
         
         for(var i:int=0;i<pixel_max;i++) {
             
             drawPixel(image_array[i].color, pixel_x, pixel_y);
             image_array[i].start_x = pixel_x;
             image_array[i].start_y = pixel_y;
             
             d = i % stage.stageWidth;
             
             if(d == 0 && i != 0) {
                 pixel_x = 0;
                 pixel_y++;
             }

             pixel_x++;
         }
         
         addEventListener(Event.ENTER_FRAME, onEnterFrame);
       }
       
       private function drawPixel(color:uint, x:int, y:int):void
       {
           var bitmap_data:BitmapData = new BitmapData(1, 1, false, color);
           buffer.copyPixels(bitmap_data, bitmap_data.rect, new Point(x, y));
       }
       
       private function erasePixel(x:int, y:int):void
       {
           var bitmap_data:BitmapData = new BitmapData(1, 1, false, 0xffffff);
           buffer.copyPixels(bitmap_data, bitmap_data.rect, new Point(x, y));
       }
       
       private function onEnterFrame(e:Event):void
       {
           for(var i:int=0;i<50;i++) {
              if(pixel_n >= pixel_max) {
                  removeEventListener(Event.ENTER_FRAME, onEnterFrame);
                  break;
              }
              
              drawPixel(image_array[pixel_n].color, image_array[pixel_n].x + image_x, image_array[pixel_n].y + image_y);
              erasePixel(image_array[pixel_n].start_x, image_array[pixel_n].start_y);
              pixel_n++;
           }
       }
   }
}


import flash.display.*;
import flash.geom.*;

class Pixel
{
    public var color:uint;
    public var x:int;
    public var y:int;
    public var start_x:int;
    public var start_y:int;

    public function Pixel(color:uint, x:int, y:int)
    {
        this.color = color;
        this.x = x;
        this.y = y;
    }
}