Hello,
I'm making a program that when you run it, an images is broken up pixel by pixel into 'particles.' And when the mouse is moved along the x-axis, the picture comes back together from the pieces that are at the bottom of the screen. Right now I have all the pixels loaded into an array, and it properly breaks up into 'particles,' but it breaks up as I move the mouse across the screen, instead of the opposite way. I was wondering where in the code that it's backwards? or if I can just start a screen with all the pixels loaded like particles, then have them somehow form a picture from that?
My code so far is:
Code:
PImage food;
int columns, rows;
int cellsize = 2;
int[][] values;
void setup(){
size(640, 480, P3D);
food = loadImage("sushi.jpg");
food.loadPixels();
values = new int[food.width][food.height];
columns = food.width / cellsize;
rows = food.height / cellsize;
for (int y = 0; y < food.height; y++){
for (int x = 0; x < food.width; x++){
color pixel = food.get(x, y);
values[x][y] = int (brightness(pixel));
}
}
}
void draw(){
background(0);
/*for (int y = 0; y < food.height; y++){
for (int x = 0; x < food.width; x++){
stroke(values[x][y]);
point (x, y, -values[x][y]);
}
}*/
for (int i = 0; i < columns; i++) {
for (int j = 0; j < rows; j++) {
float sx = map(mouseX, 0, width/2, 0, width);
int x = i*cellsize + cellsize/2;
int y = j*cellsize + cellsize/2;
int loc = x + y*food.width; // Pixel array location
color c = food.pixels[loc];
float z = (sx / float(width)) * brightness(food.pixels[loc]) - 50;
pushMatrix();
translate(x, y, z);
fill(c);
noStroke();
//point(x, y, -values[x][y]);
//stroke(values[x][y]);
rectMode(CENTER);
rect(0, 0, cellsize, cellsize);
popMatrix();
}
}
}