flash on 2010-12-16
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/gj0g
*/
package {
import flash.text.TextField;
import flash.net.*;
import flash.display.*;
import flash.system.*;
import flash.geom.*;
import flash.events.*;
import jp.progression.commands.net.*;
public class Test extends Sprite {
private var _tf : TextField;
private var _bmd : BitmapData;
public function Test() {
_tf = new TextField();
_tf.width = 465;
_tf.height = 465;
addChild(_tf);
var lu : LoadURL = new LoadURL(new URLRequest("http://api.flickr.com/services/feeds/photos_public.gne"),
{
onComplete : function() : void{
var xml : XML = XML(lu.data);
var ns : Namespace = new Namespace("http://www.w3.org/2005/Atom");
var hrefs : Array = [];
var xl : XMLList = xml..ns::link.(@rel == "enclosure").@href;
for(var i : uint = 0;i < xl.length();i++){
hrefs.push(xl[i].toString());
}
// stm*zbo
for(i = 0;i < hrefs.length && /_[ozb]\./.test(hrefs[i]);i++){}
if(i < hrefs.length){
var url : String = hrefs[i];
tr(url);
var lb : LoadBitmapData = new LoadBitmapData(new URLRequest(url), {
context : new LoaderContext(true),
onComplete : function() : void{
_bmd = lb.data as BitmapData;
process();
},
onError : function() : void {
tr("error");
},
onProgress : function() : void {
tr(lb.percent);
}
});
lb.execute();
}
}
});
lu.execute();
}
private var _data : Array;
public function process() : void
{
tr(_bmd.width, _bmd.height);
var r : Array = new Array(256);
var g : Array = new Array(256);
var b : Array = new Array(256);
for(var i : uint = 0;i < 256;i++){
b[i] = i & (255 - 15);
g[i] = (i & (255 - 15))<<8;
r[i] = (i & (255 - 15))<<16;
}
var nya : BitmapData = _bmd.clone();
nya.paletteMap(_bmd, _bmd.rect, new Point(), r, g, b);
/*
_data = [];
_bmd.lock();
for(var y : uint = 0;y < _bmd.height;y++){
for(var x : uint = 0;x < _bmd.width;x++){
var w : uint = Math.random() * Math.min(_bmd.width - x, 50) + 1;
var h : uint = Math.random() * Math.min(_bmd.height - y, 50) + 1;
var c : uint = _bmd.getPixel(x, y);
for(var xx : uint = x; xx < x + w;xx++){
for(var yy : uint = y; yy < y + h;yy++){
_bmd.setPixel(xx, yy, _bmd.getPixel(xx, yy) ^ c);
}
}
_data.push({x:x, y:y, c:c, w:w, h:h});
}
}
_bmd.unlock();
tr(_data.length);
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// shuffle
for(var i : uint = 0;i < _data.length - 1;i++){
var j : uint = Math.random() * (_data.length - i - 2) + i + 1;
var d : Object = _data[i]; _data[i] = _data[j]; _data[j] = d;
}
*/
addChild(new Bitmap(_bmd));
var bmp : Bitmap = new Bitmap(nya);
bmp.y = 240;
addChild(bmp);
}
private var _step : uint = 0;
public function onEnterFrame(e : Event) : void
{
if(_step == _data.length){
removeEventListener(Event.ENTER_FRAME, onEnterFrame);
return;
}
var mask : BitmapData = new BitmapData(_data[_step].w, _data[_step].h, false, _data[_step].c);
var mat : Matrix = new Matrix(1, 0, 0, 1, _data[_step].x, _data[_step].y);
_bmd.draw(mask, mat, null, BlendMode.INVERT);
_bmd.draw(mask, mat, null, BlendMode.SCREEN);
mask.dispose();
/*
var sh : Shape = new Shape();
sh.graphics.beginFill(_data[_step].c);
sh.graphics.drawRect(_data[_step].x, _data[_step].y, _data[_step].w, _data[_step].h);
sh.graphics.endFill();
_bmd.draw(sh, null, null, BlendMode.SCREEN);
*/
_step++;
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
}
}
}