Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

question about what i did wrong

$
0
0

my Code:

import processing.video.*;

Capture video;



void setup() {
  size(640, 480);
  pixelDensity(1);
  frameRate(60);
  String[] cameras = Capture.list();
  printArray(cameras);
  video = new Capture(this, cameras[1]);
  video.start();
}

void captureEvent(Capture video) {
  video.read();
}



void draw() {

  video.loadPixels();
  image(video, 0, 0);
  grid();
}

void grid() {
  int square = 0;
  int nr = 20;
  int[] avg = new int[width * height];
  background(255, 0, 0);
  loadPixels();
  if (width % nr == 0 & height % nr == 0) {
    for (int s1 = 0; s1 < height; s1 += height/nr) {
      for (int s2 = 0; s2 < width; s2 += width/nr) {

        for (int x = 0; x < width/nr; x++) {
          for (int y = 0; y < height/nr; y++) {
            square = (x + y * width) + s1 * width + s2;
            avg[square] = int(brightness(get(x + s2, y + s1 * width)));
            pixels[square] = color(avg[square]);
          }
        }

      }
    }
    updatePixels();
  }
}

END

when i run this code it only shows me a black screen. I already tried the same code with just slightly changed for() loops

void grid() {
  int[] avg = new int[width*height];
  loadPixels();
  for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
      avg[x+y*width] = int(brightness(get(x,y)));
      pixels[x+y*width] = color(avg[x+y*width]);
    }
  }
  updatePixels();
}

and it worked 100% correct, so I assume the problem must be in the for() loops or how i used the variables s1 and s2, but I just can not find the mistake. Thanks in advance.

~sLucas


Viewing all articles
Browse latest Browse all 2896

Trending Articles