Agrega un filtro de píxel art a la cámara de video

import processing.video.*;
Capture cam;
void setup() {
size(640, 480);
cam = new Capture(this, width, height);
cam.start();
rectMode(CENTER);
}
void draw() {
background(0);
if (cam.available()) {
cam.read();
}
loadPixels();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width / 2; x++) {
int loc1 = x + y * width;
int loc2 = (width - x - 1) + y * width;
pixels[loc1] = cam.pixels[loc2];
pixels[loc2] = cam.pixels[loc1];
}
}
updatePixels();
int rectSize = 20;
int numRects = width / rectSize;
for (int i = 0; i < numRects; i++) {
for (int j = 0; j < numRects; j++) {
int rectX = i * rectSize + rectSize / 2;
int rectY = j * rectSize + rectSize / 2;
float col = brightness(get(rectX, rectY));
fill(col);
rect(rectX, rectY, rectSize, rectSize);
}
}
}