forked from: forked from: flash on 2009-5-26
forked from forked from: flash on 2009-5-26 (diff: 49)
ActionScript3 source code
/**
* Copyright set0 ( http://wonderfl.net/user/set0 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vJUb
*/
// 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_x:int = 0;
private var pixel_y:int = 0;
private var pixel_n:int = 0;
private var pixel_max:int = 0;
private var tween_n:int = 0;
private var image_array:Array = [];
private var sp_array:Array = [];
public function FlashTest()
{
Wonderfl.capture_delay(120);
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
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:int = 0;
for(var img_y:int=1;img_y<=image_height;img_y++) {
for(var img_x:int=1;img_x<=image_width;img_x++) {
image_array[count] = [];
image_array[count]["color"] = getColorArray(base.getPixel(img_x, img_y));
image_array[count]["x"] = String(img_x + image_x);
image_array[count]["y"] = String(img_y + image_y);
count++;
}
}
pixel_max = image_array.length;
image_array.sortOn("color", Array.DESCENDING);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void
{
for(var i:int=0;i<80;i++) {
if(pixel_n >= pixel_max) {
if(tween_n >= pixel_max) {
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
break;
}
for(var n:int=0;n<80;n++) {
//BetweenAS3.tween(sp_array[tween_n], {x:int(image_array[tween_n]["x"]), y:int(image_array[tween_n]["y"])}).play();
sp_array[tween_n].x = int(image_array[tween_n]["x"]);
sp_array[tween_n].y = int(image_array[tween_n]["y"]);
tween_n++;
}
return;
}
drawPixel(pixel_x, pixel_y);
var d:int = pixel_n % image_width;
if(d == 0 && pixel_n != 0) {
pixel_x = 0;
pixel_y++;
}
pixel_x++;
pixel_n++;
}
}
private function drawPixel(x:int, y:int):void
{
var sp:Sprite = new Sprite();
addChild(sp);
sp.graphics.lineStyle(1, image_array[pixel_n]["color"], 1.0, false, "none");
sp.graphics.moveTo (0, 0);
sp.graphics.lineTo(1, 1);
sp.x = x + image_x;
sp.y = y;
sp_array[pixel_n] = new Sprite();
sp_array[pixel_n] = sp;
}
private function getColorArray(c:Number):String
{
var c_string:String = "0x" + getRgbString(c);
return c_string;
}
private function getRgbString(c:Number):String
{
var rgb:String = ("00000" + c.toString(16)).substr(-6).toUpperCase();
return rgb;
}
}
}