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 › N00B - Reading H,S,B from pixel on mouse click.
Page Index Toggle Pages: 1
N00B - Reading H,S,B from pixel on mouse click. (Read 578 times)
N00B - Reading H,S,B from pixel on mouse click.
Nov 22nd, 2006, 9:29pm
 
I'm using processing as a nice way to create "Photoshop-like" filters for post processing digital images.

I can read the photograph and set it as the background. Easy enough. I also have used vectors, particles, and a particle system as classes to generate crude particle motion (easy enough from examples).

But now I'd like to have the particles interact with the image and I'm stuck.

I have a particle system with the variables:
X position,
Y position,
H,
S,
B,
Transparency.

--------------------------------------------------
ps.addParticle(mouseX,mouseY,random(1,255),random(1,255),random(1,255),50);
--------------------------------------------------

Instead of random numbers I'd like to feed in the H,S,B values of the pixel of an image from the mouse click - basically from the X or Y position read in the existing H,S,B.

I'd like to play with taking a pixel of a photograph and having it move and mix with the other pixels.

Sort of like the smoke animations on this site but with the smoke as an actual pixel that "burns" through a saturation loss and brightness loss as it moves, and does not just overlay or mix using brightness but actually mixes with the existing pixel.

Any ideas?

I've tried to combine pixels[] with hue(), etc. without luck.
Re: N00B - Reading H,S,B from pixel on mouse click
Reply #1 - Nov 23rd, 2006, 9:33am
 
So here's how I would go about loading in the color of the pixel under the mouse:

Code:

color c = get(mouseX, mouseY);


Or, if you want, you can replace mouseX or mouseY with whatever coordinate defining variable or function you prefer. Just as a way to typecheck something like that, though, I would pass those values mod (%) the width and height, respectively so that you aren't pulling pixels outside the canvas.

From there, you can pull the H S or B value using any of the Processing methods for color. I hope this helps!
Re: N00B - Reading H,S,B from pixel on mouse click
Reply #2 - Nov 23rd, 2006, 4:57pm
 
Thanks Matt...

I have the H,S,B as a single array as type color and the postition as a vector type, so actually grabbing the color this way is an excellent method.

Using modulo on a percent... very creative. I never would have thought of that and I'm going to remember that neat trick.
Page Index Toggle Pages: 1