I would like to setup a display with CMYK colors chosen randomly every time by Processing (see the exemple in attach but I need one with one colour per pixel and not group of pixels per colour as in the image attached). Thanks for your help
you could make the group’ size only 1x1 pixel rectangle or use the point() function with a randomly selected color for each pixel in the window
may be try this
/*
CMYK to RGB conversion formula
The R,G,B values are given in the range of 0..255.
The red (R) color is calculated from the cyan (C) and black (K) colors:
R = 255 × (1-C) × (1-K)
The green color (G) is calculated from the magenta (M) and black (K) colors:
G = 255 × (1-M) × (1-K)
The blue color (B) is calculated from the yellow (Y) and black (K) colors:
B = 255 × (1-Y) × (1-K)
*/
color cymk2rgb(float c, float y, float m, float k)
{
return color(255 * (1-c) * (1-k), 255 * (1-m) * (1-k), 255 * (1-y) * (1-k), 255);
}
void setup()
{
size (200, 200);
colorMode(RGB); // that's the default, so not really needed. just to show this has of course an influence
}
void draw()
{
// if (keyPressed == true) // uncomment this if you want to display a new drawing each time you press a key (after selecting the window)
for (int i=0; i<width; i++)
for (int j=0; j<height; j++) {
stroke(cymk2rgb(random(1), random(1), random(1), 0)); // using 0 for K to minimize black component and get more colorful output, could be also random(1) or random(0.5)
point(i, j);
}
}
then you don’t need the cymk2rgb() function, just build a random color
void setup()
{
size (200, 200);
}
void draw()
{
// if (keyPressed == true) // uncomment this if you want to display a new drawing each time you press a key (after selecting the window)
for (int i=0; i<width; i++)
for (int j=0; j<height; j++) {
stroke(color(int(random(256)), int(random(256)), int(random(256))));
point(i, j);
}
}