GMU:Processing im Park/Emilio Aguas/sample code test07

From Medien Wiki

--- Processing3.0 Code---

Z depth according to the brightness values of the pixels

PImage img;
int pixs = 4;
int colums, rows;


void setup() {
  size (900, 600, P3D);
  background (0);
  smooth ();
  noStroke();

  img= loadImage ("IMG_0243.jpg");
  colums = width/pixs;
  rows= height/pixs;
}


void draw () {
  loadPixels ();
  for (int i = 0; i < colums; i++) {
    for (int j = 0; j < rows; j++) {
    
    int x = ((i * pixs) + (pixs/2));
    int y = ((j * pixs) + (pixs/2));
    int pixel_loc = x + (y * img.width);
    color image = img.pixels[pixel_loc];
    float z = (mouseX/ (float) width) * brightness(img.pixels[pixel_loc]) - 250;
    
    pushMatrix();
    translate (x, y, z);
    fill (image);
    rectMode (CORNER);
    rect(0, 0, pixs, pixs);
    popMatrix();
    }
  }
}