Hi, I got a prob...
the error is caused by this line:
for (int i = 0; i < out.pixels.length; i+= 3){
if I change it to i += 4); then it works but I get caps in the drawning lines.
the curve code is based on:
Code:noFill();
beginShape();
curveVertex(84, 91);
curveVertex(84, 91);
curveVertex(68, 19);
curveVertex(21, 17);
curveVertex(32, 100);
curveVertex(32, 100);
endShape();
I know how the error is caused but I don't know a way to solve it.
Code:import processing.video.*;
//import processing.opengl.*;
PImage out = new PImage();
Capture cam;
String cMode = "HSB";
//String dMode = "point";
void setup(){
size(600, 600, P3D);
frameRate(10);
smooth();
noFill();
rectMode(CENTER);
cam = new Capture(this, 10, 10);
}
void draw() {
background(204);
pushMatrix();
translate(width/2, height/2, 0);
rotateX( radians(mouseY));
rotateY( radians(mouseX));
//scale(2.0);
//box(250);
translate( -128, -128, -128);
if (cam.available() == true) {
cam.read();
//image(cam, 0, 0); //set(160, 100, cam);
out.pixels = sortArray(cam.pixels, 0);
//strokeWeight(4);
for (int i = 0; i < out.pixels.length; i+= 3){
stroke(color(out.pixels[i]));
beginShape();
if (cMode == "RGB"){
curveVertex(red(out.pixels[i]), green(out.pixels[i]), blue(out.pixels[i]));
}
else if(cMode == "HSB"){
curveVertex(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));
curveVertex(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));
curveVertex(hue(cam.pixels[i+1]), saturation(cam.pixels[i+1]), brightness(cam.pixels[i+1]));
curveVertex(hue(cam.pixels[i+2]), saturation(cam.pixels[i+2]), brightness(cam.pixels[i+2]));
curveVertex(hue(cam.pixels[i+3]), saturation(cam.pixels[i+3]), brightness(cam.pixels[i+3]));
curveVertex(hue(cam.pixels[i+3]), saturation(cam.pixels[i+3]), brightness(cam.pixels[i+3]));
//point(hue(cam.pixels[i]), saturation(cam.pixels[i]), brightness(cam.pixels[i]));
}
endShape();
}
}
if (frameCount % 15 == 0){
saveFrame();
}
popMatrix();
}
//DUMP
//rotateY(map(mouseX, 0, width, -PI, PI));
//rotateX(map(mouseY, 0, height, PI, -PI));
int[] sortArray(int[] tosort, int depth) {
int[][] contents = new int[256][];//256 levels for RGB/hue/brightness/etc
int[] counts = new int[256];//256 levels for RGB/hue/brightness/etc
int[] indexlist = new int[tosort.length];
int[] sorted = new int[tosort.length];
//Pass 1
int tx = 0;
for (int i=0; i<tosort.length; i++) {
switch (depth) {//This sort sequence orders them by hue then brightness
case 0:
indexlist[i] = int(hue(tosort[i]));//alpha
break;
default:
indexlist[i] = int(brightness(tosort[i]));//target
}
counts[indexlist[i]]++;//increment the count table
}
//Pass 2
for (int i=0; i<256; i++) {
contents[i] = new int[counts[i]];
//output.println("contents["+i+"] is "+contents[i].length);
}
//Pass 3
for (int i=0; i<tosort.length; i++) {
contents[ indexlist[i] ][ contents[indexlist[i]].length - counts[indexlist[i]] ] = tosort[i];
counts[indexlist[i]]--;//back down the count table
}
if ( (depth >= 0) && (depth < 4) ) {//=======================recursion call===============
for (int i=0; i<256; i++) {
if (contents[i].length > 0) {
switch (depth) {//Sort by hue then brightness
case 0:
contents[i] = sortArray(contents[i], 1);
break;
default:
//indexlist[i] = int(brightness(tosort[i]));//target
}
}
}
}
//Pass 4
int idx = 0;//Location to place into output
for (int i=0; i<contents.length; i++) {//outer array size
for (int d=0; d<contents[i].length; d++) {
sorted[idx] = contents[i][d];
idx++;
}
}
return sorted;
}