Visual Experiment 14 (Processing)

Tags:

This is a variant of Visual Experiment 03. Unlike the previous one, this experiment generates a static image with a mosaic effect. This effect is achieved through a nested loop that draws circles, which take on the color and brightness of the pixels from the original image.

PImage img;
int step = 10; 

void setup() {
  size(600, 400);
  img = loadImage("josé_chávez_morado.jpg");
  img.resize(width, height);
  background(0);
  noStroke();
}

void draw() {

  for (int y = 0; y < height; y += step) {
    for (int x = 0; x < width; x += step) {

      color pixelColor = img.get(x, y);

      float brightness = brightness(pixelColor);

      float diameter = map(brightness, 0, 255, 0, step * 1.5);
      
      fill(pixelColor); 
      ellipse(x, y, diameter, diameter);
    }
  }
  noLoop(); 
}