Convolution Rice Shower
/**
* Copyright uwi ( http://wonderfl.net/user/uwi )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/6Kgj
*/
package {
import flash.display.Sprite;
import flash.text.TextField;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.filters.*;
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);
graphics.beginFill(0x000066);
graphics.drawRect(0, 0, 465, 465);
graphics.endFill();
_bmd = new BitmapData(465, 465, true, 0x00000000);
addChild(new Bitmap(_bmd));
addEventListener(Event.ENTER_FRAME, onEnterFrame);
// _bmd.setPixel32(100, 100, 0xffffffff);
_cf = new ConvolutionFilter(3, 7, [
0, 0.3, 0,
0.08, 0.3, 0.08,
0.08, 0.2, 0.08,
0, 0.1, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0
], 1.0, 0.0, false);
}
private var _cf : ConvolutionFilter;
private var _step : Number = -99999;
public function onEnterFrame(e : Event) : void
{
_bmd.lock();
if(_step % 10 == 0){
_bmd.setPixel32(Math.random() * 465, Math.random() * 30 + 5, 0xff000000 + Math.random() * 0xffffff);
}
_step++;
_bmd.applyFilter(_bmd, _bmd.rect, new Point(), _cf);
_bmd.unlock();
}
private function tr(...o : Array) : void
{
_tf.appendText(o + "\n");
}
}
}