Pixel window setup

Hi,

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

Humus

Colors chosen randomly by Processing from the all range of CMYK colours

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);
    }
}

hi Jay, thanks for your reply. How to setup it with RGB colors (and not CMYK)?
Thanks!

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);
    }
}

(typed here, so mind typos)

Alternative version using set() in place of point():

void setup() {
  size(600, 600);
  noLoop();
}

void draw() {
  for (int y = 0; y < height; ++y)  for (int x = 0; x < width; ++x)
    set(x, y, (color) random(#000000));
}

void mousePressed() {
  redraw();
}

void keyPressed() {
  redraw();
}

A more performant version using pixels[]:

void setup() {
  size(600, 600);
  noLoop();
  loadPixels();
}

void draw() {
  for (int i = 0; i < pixels.length; pixels[i++] = (color) random(#000000));
  updatePixels();
}

void mousePressed() {
  redraw();
}

void keyPressed() {
  redraw();
}

this is indeed much better @GoToLoop

Hi Guys,

do you know if there is some exemple that, starting from a random pixel display, do some animation by some rules ?

Thanks
Best regards
Roberto

Conway’s game of life is a nice place to start.

thanks. How to export it to be shown, for exemple, embedded in a Power Point presentation demo?
thanks

can powerpoint play a Java program? probably simpler to record a small video of the screen and put the movie in PPT