xor texture
/**
* Copyright codeonwort ( http://wonderfl.net/user/codeonwort )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/tPAJ
*/
package {
import flash.geom.Point;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var gen:Array = [f0, f1, f2, f3, f4, f5, f6]
private var idx:int = 0
private var f:Function = gen[0]
private var bd:BitmapData
public function FlashTest() {
// write as3 code here..
bd = new BitmapData(512, 512, false)
draw()
with(addChild(new Bitmap(bd))) { width = height = 465 }
stage.addEventListener("mouseDown", function($:Object):void {
idx = (idx + 1) % gen.length
f = gen[idx]
draw()
})
}
private function draw():void {
for(var i:int=0; i<512; i++){
for(var j:int=0; j<512; j++){
bd.setPixel(i, j, f(i, j))
}
}
bd.copyChannel(bd, bd.rect, new Point, 4, 1)
bd.copyChannel(bd, bd.rect, new Point, 4, 2)
}
private function f0(i:uint, j:uint):uint {
return i ^ j
}
private function f1(i:uint, j:uint):uint {
return (128 + Math.cos(i/512*2*Math.PI) * 127) ^ j
}
private function f2(i:uint, j:uint):uint {
return (128 + Math.cos(i/512*2*Math.PI) * 127) ^ (128 + Math.sin(j/512*2*Math.PI) * 127)
}
private function f3(i:uint, j:uint):uint {
return (i + j) ^ (i - j)
}
private function f4(i:uint, j:uint):uint {
return (i * j) ^ j
}
private function f5(i:uint, j:uint):uint {
return i*i ^ j*j
}
private function f6(i:uint, j:uint):uint {
return (i/j)*127 ^ j
}
}
}