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 › Help..loadPixels random position
Page Index Toggle Pages: 1
Help..loadPixels random position (Read 490 times)
Help..loadPixels random position
Oct 19th, 2009, 12:05pm
 
Hi all,

I am trying to modify the pixels of an image based on the movement of the mouse. I know it is basic, but i am having a hard time figuring out how to do the following:

As mouseY increases, i would like to have the % of the image pixels that appear in the sketch increase. HOWEVER, how can i make this happen so that their position is random, but there quantity is still  related to the mouseY value. Here is my basic attempt without random positioning

PImage arch;

void setup() {
 size(449, 315);
 arch = loadImage("housingthun02.jpg");
}

void draw() {
 background(arch);  
 loadPixels();
 for (int i = 0; i < width*height; i++) {
   color p = pixels[i]; //
   float r = red(p);
   float g = green(p);
   float b = blue(p);
   float bw = (r + g + b) / 3.0;
   bw = constrain(bw + mouseY, 0, 255);
   pixels[i] = color(bw);    
}
updatePixels();
line(0, mouseY, 50, mouseY);
}


Any help would be greatly appreciated. Thanks
Re: Help..loadPixels random position
Reply #1 - Oct 20th, 2009, 1:52am
 
I don't understand what you mean by "% of the image pixels that appear in the sketch increase"
You mean like a transition where a number of pixels randomly chosen in the image are displayed and the remainder is black (or white, etc.)?
Re: Help..loadPixels random position
Reply #2 - Oct 20th, 2009, 1:19pm
 
Maybe this does what you want:

Code:
void draw() {
 background(arch);  
 loadPixels();
 for (int i = 0; i < width*height; i++) {
  if (random(1) < (float)mouseY/height)  // with probability proportional to mouse Y position...
    pixels[i] = color(0);  // ... erase this pixel
 }
 updatePixels();
 line(0, mouseY, 50, mouseY);
}

If you want to have non-dynamic noise, replace "random(1)" with "noise(i)", although that doesn't look as interesting.
Page Index Toggle Pages: 1