# Pixel window setup

**URL:** <https://discourse.processing.org/t/pixel-window-setup/26136>\
**Category:** Coding Questions\
**Created:** [December 11, 2020, 1:06pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136 "2020-12-11T13:06:54Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [December 11, 2020, 1:06pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/1 "2020-12-11T13:06:54Z")

</div>

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

 ![istockphoto-506819758-1024x1024](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/3f0fac5540acb15d195a468c53751add97553b1f.jpeg)

---

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [December 11, 2020, 1:07pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/2 "2020-12-11T13:07:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)\
**Post date:** [December 11, 2020, 2:33pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/3 "2020-12-11T14:33:12Z")

</div>

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

```auto
/*
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);
    }
}

```

---

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [December 11, 2020, 3:43pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/4 "2020-12-11T15:43:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)\
**Post date:** [December 11, 2020, 4:57pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/5 "2020-12-11T16:57:45Z")

</div>

then you don’t need the `cymk2rgb()` function, just build a random color

```auto
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)

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [December 11, 2020, 5:31pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/6 "2020-12-11T17:31:36Z")

</div>

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

> **[set() \\ Language (API) \\ Processing 3+](https://Processing.org/reference/set_.html)**

```auto
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[]_:

> **[pixels\[\] \\ Language (API) \\ Processing 3+](https://Processing.org/reference/pixels.html)**

```auto
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();
}

```

---

<div class="post-metadata">

**Author:** ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)\
**Post date:** [December 11, 2020, 5:33pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/7 "2020-12-11T17:33:45Z")

</div>

this is indeed much better @GoToLoop

---

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [March 29, 2021, 2:27pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/8 "2021-03-29T14:27:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [March 29, 2021, 2:41pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/9 "2021-03-29T14:41:37Z")

</div>

[Conway’s game of life](https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life) is a nice place to start.

---

<div class="post-metadata">

**Author:** ![humus](https://avatars.discourse-cdn.com/v4/letter/h/e36b37/32.png) [@humus](https://discourse.processing.org/u/humus)\
**Post date:** [March 29, 2021, 3:10pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/10 "2021-03-29T15:10:08Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)\
**Post date:** [April 9, 2021, 3:17pm UTC](https://discourse.processing.org/t/pixel-window-setup/26136/11 "2021-04-09T15:17:49Z")

</div>

> [@humus](#):
>
> How to export it to be shown, for exemple, embedded in a Power Point presentation demo

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