内臓カメラで動画をインポートしそれを線で描画するプログラムを
わかりやすく解説するという課題なのですが
void drawに書いてあるプログラムが何を言っているのかさっぱりです。
申し訳ないのですが、初心者にでもわかりやすくご説明ご説明いただけると幸いです。
コードは以下のようになっております。
是非ともよろしくお願いいたします。
import processing.video.*;
Capture cam;
int SPEED = 100000;//speed of render
int TESTS = 10;
float ACCURACY = 100;
float DISTANCE = 100;//line's distance
int MAXTRIES = 20000;
int locTest;
color colTest;
int xTest;
int yTest;
float testTot;
color col;
int loc;
int x;
int y;
int count = 0;
int tries = 0;
boolean newPix = true;
//
void setup(){
size(800,600);
cam = new Capture(this,width,height,24);
background(255);
strokeWeight(1);
cam.start();
}
void draw(){
cam.read();
if(DISTANCE > 35) DISTANCE -= .1;//
if(SPEED < 4000) SPEED ++;//
for(int i = 0; i < SPEED; i++){//
if(newPix || tries > MAXTRIES){//
newPix = false;
tries = 0;
locTest = int(random(cam.pixels.length));
colTest = cam.pixels[locTest ];
xTest = locTest % cam.width;
yTest = locTest / cam.width;
float rV = colTest >> 16 & 0xFF;//red value
float gV = colTest >> 8 & 0xFF;//green value
float bV = colTest & 0xFF;//blue value
testTot = rV + gV + bV;
}
loc = int(random(cam.pixels.length));
col = cam.pixels[loc];
if(colorTest(col)){
x = loc % cam.width;
y = loc/ cam.width;
if(dist(xTest,yTest,x,y) <= DISTANCE){
stroke(colTest,40);
line(xTest,yTest,x,y);
count++;
}
}
if(count > TESTS){
newPix = true;
count = 0;
}
tries++;
}
}
boolean colorTest(color _col){
float rV = _col >> 16 & 0xFF;
float gV = _col >> 8 & 0xFF;
float bV = _col & 0xFF;
float tot = rV + gV + bV;
float perc = (testTot/tot) *100;
if(perc >= ACCURACY )
{
return true;
}else return false;
}
あなたの回答
tips
プレビュー