flash on 2010-10-4
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/iBO8
*/
package {
import flash.text.*;
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.filters.*;
public class Test extends Sprite {
private var _tf : TextField;
private var _W : uint;
private var _H : uint;
private var _original : BitmapData;
private var _mask : BitmapData;
private var _canvas : BitmapData;
public function Test() {
_tf = new TextField();
_tf.width = 465;
_tf.height = 465;
addChild(_tf);
_original = textToBitmapData("追浜", new TextFormat("arial", 100));
_W = _original.width;
_H = _original.height;
_mask = new BitmapData(_W, _H, true, 0);
_mask.threshold(_original, _original.rect, new Point(), "==", 0xffffff, 0xff000000, 0xffffff);
// addChild(new Bitmap(_mask));
_canvas = new BitmapData(_W, _H, false, 0);
dot();
addEventListener(Event.ENTER_FRAME, onEnterFrame);
addChild(new Bitmap(_canvas));
var mat : Array = [];
for(var r : uint = 0;r < 5;r++){
for(var c : uint = 0;c < 5;c++){
// mat.push(Math.min(1, 1 / ((r - 2) * (r - 2) + (c - 2) * (c - 2) + 1)));
mat.push(r == 2 && c == 2 ? 0.5 : 0.1);
}
}
_cf = new ConvolutionFilter(5, 5, mat);
}
private var _cf : ConvolutionFilter;
private var _step : uint = 0;
private function dot() : void
{
for(var x : uint = 0;x < _W;x++){
for(var y : uint = 0;y < _H;y++){
if(_original.getPixel(x, y) == 0 && _canvas.getPixel(x, y) == 0){
_canvas.setPixel(x, y, 0x223377);
return;
}
}
}
}
private function onEnterFrame(e : Event) : void
{
if(_step % 1 == 0){
_canvas.lock();
_canvas.applyFilter(_canvas, _canvas.rect, new Point(), _cf);
_canvas.copyPixels(_mask, _mask.rect, new Point());
_canvas.unlock();
}
if(_step % 10 == 0){
dot();
}
_step++;
}
private function textToBitmapData(src : String, tfmt : TextFormat) : BitmapData
{
var tf : TextField = new TextField();
tf.autoSize = "left";
tf.defaultTextFormat = tfmt;
tf.text = src;
var bmd : BitmapData = new BitmapData(tf.width, tf.height, false, 0xffffff);
bmd.draw(tf);
return bmd;
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
}
}
}