examples / processing / for-loops / random-colors

Random Colors

example processing for-loop
void setup() {
  size(200, 100);

void draw() {
  for(int y = 0; y < height; y++){
    for(int x = 0; x < width; x++){
      float r = random(256);
      float g = random(256);
      float b = random(256);
      stroke(r, g, b);
      point(x, y);

This code uses a nested for loop to loop over every pixel in the window. For each pixel, it creates a random color and draws a point with that color at that pixel.

random colors

Code Editor

See the Pen by Happy Coding (@KevinWorkman) on CodePen.

Tweak Ideas