Pxl2000
I always wanted one of these...
// forked from forresto's RainbowCam
// forked from forresto's カタカナcam
// forked from ton's マトリックスの世界へようこそ
//なんとなくマトリックスっぽいなにか
package {
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.events.Event;
import flash.media.Camera;
import flash.media.Video;
[SWF(backgroundColor=0x000000, frameRate=15)]
public class PxlCam extends Sprite {
private const W:int = 100;
private const H:int = 100;
private var video:Video = new Video(W, H);
private var videoIn:BitmapData = new BitmapData(W, H, false);
private var grayScale:Array = new Array();
private var filtered:BitmapData = new BitmapData(W, H, false);
private var display:Bitmap = new Bitmap(filtered);
public function PxlCam():void {
var cam:Camera = Camera.getCamera();
cam.setMode(W, H, 15, true);
video.attachCamera(cam);
addChild(display);
display.width = 465;
display.height = 465;
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}
private function onEnterFrame(e:Event):void {
videoIn.draw(video);
for (var i:int = 0; i < W; i++) {
for (var j:int = 0; j < H; j++) {
var thisLum:int = rgb2lum(videoIn.getPixel(i, j));
var thisGray:int = int(grayScale[j*W+i]*.9+thisLum*.1);
grayScale[j*W+i] = thisGray;
var thisRGB:int = thisGray << 16 | thisGray << 8 | thisGray;
filtered.setPixel(i, j, thisRGB);
}
}
}
private function rgb2lum(color:int):int {
//Luminance (standard, objective): (0.2126*R) + (0.7152*G) + (0.0722*B)
//Luminance (perceived option 1): (0.299*R + 0.587*G + 0.114*B)
//Luminance (perceived option 2, slower to calculate): sqrt( 0.241*R^2 + 0.691*G^2 + 0.068*B^2 )
return int(0.299 * (color >>> 16 & 0xFF)) + (0.587 * (color >>> 8 & 0xFF)) + (0.114 * (color & 0xFF));
}
}
}