Processing – Transform

acrylic1acrylic2acrylic3acrylic4

/**
 * Transform: Transcoded Landscape [messed up by... kj]
 * from Form+Code in Design, Art, and Architecture 
 * by Casey Reas, Chandler McWilliams, and LUST
 * Princeton Architectural Press, 2010
 * ISBN 9781568989372
 * 
 * This code was written for Processing 1.2+
 * Get Processing at http://www.processing.org/download
 * 
 * You need a grayscale .jpg image [lower resolution] 
 * in the processing sketch folder */
 
 
import processing.opengl.*;
PImage img;
int[][] values;
float angle;
void setup() {
 size(1024, 768, OPENGL);
 noFill();
 
 values = new int[width][height];
// Extract the brightness of each pixel in the image
 // and store in the "values" array
 // place grayscale .jpg in sketch folder
 img = loadImage("jnznbrktest.jpg"); // rename to suit file name
 img.loadPixels();
 for (int i = 0; i < img.height; i++) {
 for (int j = 0; j < img.width; j++) {
 color pixel = img.pixels[i*img.width + j];
 values[j][i] = int(brightness(pixel));
 }
 }
}
void draw() {
 
 background(0); // Set black background
 translate(width/2, height/2, 0); // Move to the center
 scale(3.0); // Scale to 400%
 
 // Update the angle
 angle += 0.001;
 rotateY(angle); 
 
 // Display the image mass
 for (int i = 0; i < img.height; i += 1) {
 for (int j = 0; j < img.width; j += 1) {
 stroke(255, 255);
 float x1 = j-img.width/2;
 float y1 = i-img.height/2;
 float z1 = -values[j][i]/2;
 float x2 = j-img.width/2;
 float y2 = i-img.height/2;
 float z2 = -values[j][i]/2-4;
 line(x1, y1, z1, x2, y2, z2);
 }
 }
}
Advertisements

Tags: , , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: