forked from: flash on 2011-10-10
ah, doing things in pixelbender that obviously don't need to be done in pixelbender.
// forked from kihon's flash on 2011-10-10
package {
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.geom.*;
import flash.utils.*;
public class FlashTest extends Sprite {
private static const WIDTH:int = 64;
private static const HEIGHT:int = 64;
private static const ITERATIONS:int = 6;
private static const fillProbability:Number = 0.4;
private static const r:Rectangle = new Rectangle(0, 0, WIDTH, HEIGHT);
private static const p:Point = new Point();
private static const sf:ShaderFilter = new ShaderFilter(new Shader(ba(545, [-1593769472,810831,1970553711,1869767680,-1560279949,1919090849,33816832,258241396,3277312,-2134933504,3277312,1077903360,3277312,549453824,3277312,272662528,3278080,-1073741824,3278080,541106176,3278080,272629760,1901312,-218103807,66304,-1308491752,3146752,-251461584,66816,1074003968,3146752,-251461520,66816,1074003968,3146752,-251461456,66816,1074003968,66304,268566592,3146752,-251461584,66816,-2147221504,3146752,-251461520,66816,-2147221504,3146752,-251461456,66816,-2147221504,66304,268566592,3146752,-251461584,66816,-2147221504,3146752,-251461520,66816,-2147221504,3146752,-251461456,66816,-2147221504,66304,268566592,3146752,-251461584,66816,-2147221504,3146752,-251461520,66816,-2147221504,3146752,-251461456,66816,-2147221504,66304,268566592,3146752,-251461584,66816,1074003968,3146752,-251461520,66816,1074003968,3146752,-251461456,66816,1074003968,1901312,-218103787,66304,-771620732,3146752,-251461616,66816,1074003968,3146752,-251461600,66816,1074003968,3146752,-251461584,66816,1074003968,66304,-2147352384,3146752,-251461616,66816,1074003968,3146752,-251461600,66816,1074003968,3146752,-251461584,66816,1074003968,66816,1074069504,722176,-2147155840,722176,268763200,1900800,-502988800,65792,-502988548,3277056,272596992,0])));
private var noise:BitmapData;
private var bds:Array;
public function FlashTest() {
transform.colorTransform = new ColorTransform(-1, -1, -1, 1, 255, 255, 255, 0);
graphics.beginFill(0xffffff);
graphics.drawRect(0, 0, 465, 465);
noise = new BitmapData(WIDTH, HEIGHT, false, 0x000000);
bds = [];
for (var i:int = 0; i <= ITERATIONS; i++) {
bds[i] = new BitmapData(WIDTH, HEIGHT, false, 0x000000);
addChild(new Bitmap(bds[i])).x = WIDTH * i;
}
draw(null);
stage.addEventListener(MouseEvent.CLICK, draw);
}
private function draw(e:Event):void {
noise.noise(Math.random() * int.MAX_VALUE, 0, 255, 0, true);
bds[0].fillRect(r, 0x000000);
bds[0].threshold(noise, r, p, '<', 256 * fillProbability, 0xffffffff, 0xff, false);
fillEdge(bds[0]);
for (var i:int = 1; i <= ITERATIONS; i++) {
bds[i].applyFilter(bds[i - 1], r, p, sf);
fillEdge(bds[i]);
}
}
private function fillEdge(bd:BitmapData):void {
bd.fillRect(new Rectangle(0, 0, WIDTH, 1), 0xffffff);
bd.fillRect(new Rectangle(0, HEIGHT - 1, WIDTH, 1), 0xffffff);
bd.fillRect(new Rectangle(0, 1, 1, HEIGHT - 2), 0xffffff);
bd.fillRect(new Rectangle(WIDTH - 1, 1, 1, HEIGHT - 2), 0xffffff);
}
private static function ba(l:int, d:Array):ByteArray {
var r:ByteArray = new ByteArray();
for each (var w:int in d)
r.writeInt(w);
r.length = l;
return r;
}
}
}
/*
parameter "_OutCoord", float2, f0.rg, in
texture "src", t0
parameter "dst", float4, f1, out
set f2.r, -1
set f2.g, 1
set f2.b, -2
set f2.a, 4
set f5.rg, 0
set f5.b, 5
set f5.a, 2
mov f3.rgba, f0.rrrg
add f3.rba, f2.rgb
texn f4, f3.ra, t0
add f5.g, f4.r
texn f4, f3.ga, t0
add f5.g, f4.r
texn f4, f3.ba, t0
add f5.g, f4.r
add f3.a, f2.g
texn f4, f3.ra, t0
add f5.r, f4.r
texn f4, f3.ga, t0
add f5.r, f4.r
texn f4, f3.ba, t0
add f5.r, f4.r
add f3.a, f2.g
texn f4, f3.ra, t0
add f5.r, f4.r
texn f4, f3.ga, t0
add f5.r, f4.r
texn f4, f3.ba, t0
add f5.r, f4.r
add f3.a, f2.g
texn f4, f3.ra, t0
add f5.r, f4.r
texn f4, f3.ga, t0
add f5.r, f4.r
texn f4, f3.ba, t0
add f5.r, f4.r
add f3.a, f2.g
texn f4, f3.ra, t0
add f5.g, f4.r
texn f4, f3.ga, t0
add f5.g, f4.r
texn f4, f3.ba, t0
add f5.g, f4.r
mov f3.rgba, f0.rggg
add f3.rga, f2.brg
texn f4, f3.rg, t0
add f5.g, f4.r
texn f4, f3.rb, t0
add f5.g, f4.r
texn f4, f3.ra, t0
add f5.g, f4.r
add f3.r, f2.a
texn f4, f3.rg, t0
add f5.g, f4.r
texn f4, f3.rb, t0
add f5.g, f4.r
texn f4, f3.ra, t0
add f5.g, f4.r
add f5.g, f5.r
step f5.r, f5.b
step f5.a, f5.g
mov f1.rgb, f5.rrr
add f1.rgb, f5.aaa
set f1.a, 1
*/