Robot Class- getPixelColor: Anyone used this or know the best way to get it to work?
in
Programming Questions
•
3 years ago
I'm new to Processing and I have been struggling with this for several days. I want to create a program that reads a pixel color from my display and then does something according to what color(pixel) is returned. I have tried many iterations of this, seemingly, simple program and I cannot make it work. Sometimes it compiles without error and does not work and sometimes it throws errors. I was able to easily get keyPress and keyRelease (also part of Robot class) to work but this command is killing me.
My thought process is that this command (getPixelColor) returns a color so the information should be in the form of an RGB value, correct? So, I assumed I needed to create an int array to handle this color information. However, when I try to assign an int to the color value returned by the command (getPixelColor) I get an error - cannot assign a color to an int.
int [] pixelColor = new int [3];
For example, pixelColor = PixelBot.getPixelColor(100,100), throws an error.
I have also tried using this method:
color (int p){
int r =(int)red(p);
int g =(int)green(p);
int b =(int)blue(p);
println("r."+r+"g."+g+"b."+b);
return color(r,g,b);
}
The second portion of my code uses if and else if statements to use the returned color information.
I would post the entire code but it's very broken. I am just looking for the correct methodology to follow in order to use this command: getPixelColor. If I know the right path I can figure it out myself. At the moment I am on a very wild goose chase and it's driving me crazy.
Any help or suggestions would be greatly appreciated. Sorry if this question is ridiculous. I'm very new at this. : )
My thought process is that this command (getPixelColor) returns a color so the information should be in the form of an RGB value, correct? So, I assumed I needed to create an int array to handle this color information. However, when I try to assign an int to the color value returned by the command (getPixelColor) I get an error - cannot assign a color to an int.
int [] pixelColor = new int [3];
For example, pixelColor = PixelBot.getPixelColor(100,100), throws an error.
I have also tried using this method:
color (int p){
int r =(int)red(p);
int g =(int)green(p);
int b =(int)blue(p);
println("r."+r+"g."+g+"b."+b);
return color(r,g,b);
}
The second portion of my code uses if and else if statements to use the returned color information.
I would post the entire code but it's very broken. I am just looking for the correct methodology to follow in order to use this command: getPixelColor. If I know the right path I can figure it out myself. At the moment I am on a very wild goose chase and it's driving me crazy.
Any help or suggestions would be greatly appreciated. Sorry if this question is ridiculous. I'm very new at this. : )
1