Hi, I am very new to the Processing world.
I am currently working on a project using a potentiometer that determines the size of a connected video camera's Pixels.
There are two problems, (1) the range of the pot (val) is 0-255, however I can only go down to about 50 before the program freezes/gives me an ArrayOutOfBoundsException error.
(2) I was wondering if it is at all possible to stop loadPixels at some point?
here is my code, and help is greatly appreciated:
import processing.serial.*;
Serial port;
float val;
import processing.video.*;
Capture cam;
//import fullscreen.*;
//FullScreen fs;
int cellSize = 10;
int cols, rows;
void setup() {
background(000);
size(1920, 1200);
//fs = new FullScreen(this);
//fs.enter();
cols = 1920 / cellSize;
rows = 1080 / cellSize;
colorMode(RGB, 255, 255, 255, 100);
cam = new Capture(this, 2020, 1180);
size(1920,1080);
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600);
}
void draw() {
if (cam.available() == true) {
cam.read();
image(cam, 0, -120);
if (port.available() > 0) {
val = port.read();
println(val);
}
cam.loadPixels();
background(0);
float cs = float(cellSize);
cs = val;
cs = map(cs, 0, 255, 0, 45);
cols = 1920 / int(cs);
rows = 1080 / int(cs);
// Begin loop for columns
for (int i = 0; i < cols; i++) {
// Begin loop for rows
for (int j = 0; j < rows; j++) {
int x = int(i*cs);
int y = int(j*cs);
int loc = (cam.width + x - 1) + y*cam.width;
float r = red(cam.pixels[loc]);
float g = green(cam.pixels[loc]);
float b = blue(cam.pixels[loc]);
color c = color(r, g, b, 100);
pushMatrix();
translate(x+cs/2, y+cs/2);
rectMode(CENTER);
fill(c);
noStroke();
rect(i, j, cs+41, cs+14);
popMatrix();
}
}
}
}
1