Frocessingとカメラテスト
/**
* Copyright jaccoy ( http://wonderfl.net/user/jaccoy )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/vIzl
*/
package {
import frocessing.display.F5MovieClip2D;
import flash.display.*;
import flash.geom.*;
import flash.filters.*;
import flash.events.*;
import flash.media.*;
import flash.utils.*;
[SWF(width=465,height=465,backgroundColor=0xFFFFFF)]
public class GridSequencer extends F5MovieClip2D {
private var rectW:int = 15;
private var rectH:int = 15;
private var myCamera:Camera = Camera.getCamera();
private var video:Video;
private var nowFrame:BitmapData = new BitmapData(465,465,true,0xFFCCCCCC);
private var capture:Bitmap = new Bitmap( nowFrame , PixelSnapping.AUTO , true);
private var matrix:Matrix =new Matrix(-1,0,0,1,465,0);
private var colorVal:uint;
private var timeline:int;
private var setColor:String;
public function GridSequencer() {
//カメラ設定==============================================================================
// カメラソースを取得
video = new Video(465,465);
if ( myCamera != null ) {
// カメラ設定
video.attachCamera( myCamera );
myCamera.addEventListener( ActivityEvent.ACTIVITY , activityHandler );
} else {
trace("カメラを検出できないだう!");
}
function activityHandler( event:ActivityEvent ):void {
if( event.activating == true ){
trace( "カメラが動いただう!" );
}
}
//カメラの実像を表示=============================================
//addChild(capture);
//capture.alpha = 0.2;
//継続処理の追加=============================================
setInterval(xGrid, 100);
}
public function xGrid ():void{
background(0xFFFFFF);
//カメラから画像を取り込み=============================================
nowFrame.draw(video,matrix);
capture.bitmapData = nowFrame.clone();
//図形の描画=============================================
//線と塗りの指定
stroke( 0x00 );
//noStroke();
for(var j:int=0; j<465;j+=rectH){
for(var i:int=0; i<465;i+=rectW){
colorVal = capture.bitmapData.getPixel(i+rectW/2,j+rectH/2);
setColor = "0x00"+colorVal.toString(16);
fill(Number(setColor));
rect( i, j, rectW, rectH );
}
}
xTimeLine();
timeline++;
}
public function xTimeLine ():void{
noStroke();
fill( 0x33FFFFFF );
rect( timeline*rectW , 0, rectW, 465 );
if(timeline*rectW >= 465){
timeline = 0;
}
}
}
}