2011.05.07

Roto Petey

Today’s Processing sketch isn’t really mine… It’s from the extrusion example on processing.org. It’s a cool demo showing how brightness of an image can map to height in 3D.

I took the code and put my own image into it. The image is from my profile pic, cropped a bit and posterized to 5 levels of grey.

See it in action here!

This demo uses straight-up Java, not Javascript, because Processing.js doesn’t yet support all of what Processing does. (I was hoping to make a video of this but I’m having issues with the Processing MovieMaker code.)

Regular Petey

I find it useful to take code that someone else wrote, and start tweaking things, changing the values, etc. to see the outcome. I still find this code just a little confusing, but I’ll keep hacking at it to see what I can learn from it, and hope I can come up with something original myself.

/*
 * 20110507.pde
 */

PImage extrude;
int[][] values;
float angle = 0;

void setup() {
  size(800, 600, P3D);
  extrude = loadImage("pete.jpg");
  extrude.loadPixels();
  values = new int[extrude.width][extrude.height];
  for (int y = 0; y < extrude.height; y++) {
    for (int x = 0; x < extrude.width; x++) {
      color pixel = extrude.get(x, y);
      values[x][y] = int(brightness(pixel));
    }
  }
}

void draw() {
  background(0);
  angle += 0.01;

  translate(width/2, 0, -128);
  rotateY(angle);  
  translate(-extrude.width/2, 200, -180);
  
  for (int y = 0; y < extrude.height; y++) {
    for (int x = 0; x < extrude.width; x++) {
      stroke(values[x][y]);
      point(x, y, -values[x][y]);
    }
  }

}

Comments are closed.

« | »


buy the button:

Buy The Button