Please help to change the existing code that maps pixels from a 2D image into 3D space
in
Programming Questions
•
1 year ago
Here is a brilliant code from the Example section of Processing site
PImage img; // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows; // Number of columns and rows in our system
void setup() {
size(750, 500, P3D);
img = loadImage("Mirror-pixels-Pattern1.jpg"); // Load the image
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
}
void draw() {
background(0);
// Begin loop for columns
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x + 200, y + 100, z);
fill(c, 204);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
}
'Mouse horizontal location controls breaking apart of image and Maps pixels from a 2D image into 3D space.
Pixel brightness controls translation along z axis.'
please see how it works here: http://processing.org/learning/3d/explode.html
So my question: is it possible to adjust this code so that it manipulates 2 images instead of one?
I have image 1 and image 2 which are the same size,
i need to bring the pixels of image 1 the same way as if I used this code for image 2.
So that when I apply a new code for these two images
brighter pixels of not image 1 come up, but the pixels that situated on the same positions where the brighter pixels of image 2 are.
so image 2 should become the 'map' of positions for pixels of image 1
I've made a little draft to explain what i mean
hope it make sense
please ask if anything is unclear
I'm a very beginner in processing so if you could tell me how exactly i should change the code i'll be very grateful,
hope it's possible to do
Thank you in advance
PImage img; // The source image
int cellsize = 2; // Dimensions of each cell in the grid
int columns, rows; // Number of columns and rows in our system
void setup() {
size(750, 500, P3D);
img = loadImage("Mirror-pixels-Pattern1.jpg"); // Load the image
columns = img.width / cellsize; // Calculate # of columns
rows = img.height / cellsize; // Calculate # of rows
}
void draw() {
background(0);
// Begin loop for columns
for ( int i = 0; i < columns; i++) {
// Begin loop for rows
for ( int j = 0; j < rows; j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*img.width; // Pixel array location
color c = img.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = (mouseX / float(width)) * brightness(img.pixels[loc]) - 20.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
translate(x + 200, y + 100, z);
fill(c, 204);
noStroke();
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
}
'Mouse horizontal location controls breaking apart of image and Maps pixels from a 2D image into 3D space.
Pixel brightness controls translation along z axis.'
please see how it works here: http://processing.org/learning/3d/explode.html
So my question: is it possible to adjust this code so that it manipulates 2 images instead of one?
I have image 1 and image 2 which are the same size,
i need to bring the pixels of image 1 the same way as if I used this code for image 2.
So that when I apply a new code for these two images
brighter pixels of not image 1 come up, but the pixels that situated on the same positions where the brighter pixels of image 2 are.
so image 2 should become the 'map' of positions for pixels of image 1
I've made a little draft to explain what i mean
hope it make sense
please ask if anything is unclear
I'm a very beginner in processing so if you could tell me how exactly i should change the code i'll be very grateful,
hope it's possible to do
Thank you in advance
1