I think @Jakub is right.
The reference for all the blend modes: blendMode() or maybe blend(). You can use SUBSTRACT
or MULTIPLY
and try another ones. They are similar to Photoshop blending modes.
Mathematically, RGB converts directly to CMY, with no need of Black (K). Theoretically, the mix of C+M+Y should result in black. We only use Black on printing because inks are not perfect, so black ink gets better results for contrast and other details. So, when you add black ink, you need to do the math to decrease the CMY values. For more information, look for Grey component replacement.
Here is my code from before, now using blendMode(MULTIPLY)
, and mixing the color with alpha. The position of the images now can be controled with the mouse. I also hide the Black channel because I am not calculating the “Grey component replacement” (so it would only make the image darker without representing the reality).
import processing.video.*;
Capture cam;
PImage cyan;
PImage magenta;
PImage yellow;
PImage black;
int w = 640; // Webcam image width
int h = 480; // Webcam image height
void setup() {
size(1920, 960);
blendMode(MULTIPLY);
// Webcam setup
String[] cameras = Capture.list();
printArray(cameras);
cam = new Capture(this, cameras[0]);
cam.start();
// Create Images
cyan = createImage(w, h, ARGB);
magenta = createImage(w, h, ARGB);
yellow = createImage(w, h, ARGB);
black = createImage(w, h, ARGB);
}
void draw() {
if (cam.available() == true) {
background(255);
cam.read();
// LoadPixels of the images
cam.loadPixels();
cyan.loadPixels();
magenta.loadPixels();
yellow.loadPixels();
black.loadPixels();
// RGB to CMYK conversion simulation
for (int i = 0; i < cam.pixels.length; i++) {
float c_ = (255-red(cam.pixels[i]));
float m_ = (255-green(cam.pixels[i]));
float y_ = (255-blue(cam.pixels[i]));
float k_ = (255-brightness(cam.pixels[i]));
cyan.pixels[i] = color(0, 255, 255, c_);
magenta.pixels[i] = color(255, 0, 255, m_);
yellow.pixels[i] = color(255, 255, 0, y_);
black.pixels[i] = color(0, k_);
}
// UpdatePixels of the images
cyan.updatePixels();
magenta.updatePixels();
yellow.updatePixels();
black.updatePixels();
// Display the images with mouse position
image(cam, 0, 0);
image(cyan, w + 0*w, 0);
image(magenta, mouseX-w, 0);
image(yellow, w + 0*w, mouseY-h);
//image(black, mouseX-w, mouseY-h);
}
}