Help with Extrusion from 2D to 3D

Right, well, the parameters to the box() function are the size of each box. Set x and y to 1, and vary the z size based on the brightness. You also want to adjust the position because boxes are drawn from their centers:

PImage img;
boolean mono = false;

void setup() {
  size(600, 400, P3D);
  img = loadImage("http://www.tfguy44.com/MyIcon1.PNG");
  img.loadPixels();
  noStroke();
}

void draw() {
  background(mono?127:0);
  lights();
  translate(width/2, height/2);
  rotateX(-map(mouseY,0,height,-PI,PI));
  rotateY(map(mouseX,0,width,-PI,PI));
  scale(5);
  translate(-img.width/2, -img.height/2);
  fill(255);
  for (int x=0; x<img.width; x++) {
    for (int y=0; y<img.height; y++) {
      float bri = map(brightness(img.get(x, y)),0,255,0,10);
      pushMatrix();
      translate(x,y,bri/2);
      if( !mono ) fill(img.get(x, y));
      box(1,1,bri);
      popMatrix();
    }
  }
}

void mousePressed(){
  mono=!mono;
}

This isn’t a fish for you. This is a picture of me wearing my fisherman hat and holding my fishing rod and eating some fish. Study the elements that this snapshot presents and understand what they are for and how you can use them.

3 Likes