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 & HelpSyntax Questions › loading pixels in an array
Page Index Toggle Pages: 1
loading pixels in an array (Read 575 times)
loading pixels in an array
Feb 24th, 2010, 8:20pm
 
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();
     
   }
  }
}
Re: loading pixels in an array
Reply #1 - Feb 24th, 2010, 9:12pm
 
Quote:
float sx = map(width-mouseX, 0, width/2, 0, width);

Re: loading pixels in an array
Reply #2 - Feb 24th, 2010, 9:56pm
 
haha, thanks, i didn't see that xD;
thanks though that was what i wanted it to do =]
Page Index Toggle Pages: 1