We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › creating a box w/ z position determined by pixel
Page Index Toggle Pages: 1
creating a box w/ z position determined by pixel (Read 540 times)
creating a box w/ z position determined by pixel
Apr 7th, 2008, 7:23am
 
i'm attempting to write a code that will read the value of pixel and then create a box whose z position is determined by the value in the pixel.  (e.g. if the rgb of a given pixel is 200, then the z position of a (1 x 1 x 1) box is 8.  

i'm also attempting in part of the script to be able to rotate around in the 3d environment, but have been very unsuccessful so far.  

here's what i've gotten through so far and although it's not what i wanted, its yielded some interesting results...

import processing.opengl.*;

PImage img01 = loadImage("DSCN1042.jpg");
//load the image
size(img01.width, img01.height, P3D);
//set the image size as background size

int detail = 10;
for (int i=0; i<width; i+=detail) {
 for (int j=0; j<width; j+=detail) {
   color c = img01.get(i, j);
   fill(c);
   rect(i,j,detail,detail);
   //pixelate image based on the brightness value in each pixel
   //fills a rectangle with that color


   color d = img01.get(i, j);
   if (d < 200) {
     box(10,10,10);
     translate(0,0,1);
     //z position of the box is determined by the value of the pixel

   translate(width/2, 0, 128);
   rotateY(50);
   translate(-width/2, 0, 128);
     //gets the color of each pixel
     //draws a box and moves the box in the z-axis based on a value of that box
   }
 }
}





Re: creating a box w/ z position determined by pix
Reply #1 - Apr 7th, 2008, 5:06pm
 
Hey smad09, you might want to check out this example from the processing website:

http://processing.org/learning/3d/extrusion.html

I think It's pretty close to what you're trying to achieve, just replace some of the code so that instead of drawing strokes you draw a box just make sure you translate the coordinates first.  Use the get method to obtain the pixels color and map that to the Z coordinates.
Page Index Toggle Pages: 1