Hi to all
So I messed up the first step being, trying to get my code in a readable format. I saw the link to Processing.js Template, but had no idea what to do with it once my code was in there. Then there was the opportunity to place it here in the proper context, but again, I had no idea where to put, so please go easy on me as I will just copy it to this post.
My objective is to create 2 or 3 indicating lights. I want to manipulate the color(r,g,b) component to change the pixel color of the light to be green when a switch is on and red when the switch is off. For ease of understanding my code, I have left out all the switching lines of code and to change the pixel color, manually change the color(r,g,b) Green Light to color(g,r,b) a Red Light.
The light.jpg images are 127 x 127 pixels. So, here is the rub so to speak. When I enter any value except for size (127,127) in the size() function, I get the Array Index Out of Bounds Exception error. I looked it up on the WWW, but I guess I haven’t learned the language that coders speak when they describe something. It’s almost like they can take 12 random words in the dictionary and make a sentence out of them that only coders can understand. Now I have seen many examples of coders putting large number like size(800, 600) in their program, with a smaller image, and it works fine. When I enter size(127,127), I can manipulate the color() function to change the pixel colors of the Light’s lens. I would like to add a second Light and do the same thing with it. If I change the size() to size (300, 100), both lights show up in Processing’s window, but I get the same Array Out of Bounds Index, and I cannot manipulate the pixel colors.
I have changed the code around over and over and left it in the last state of change, so if you ask why I did why I did, it was what is left after I threw all the different combinations of code that my limited knowledge would allow. To sum it all up, why do I get that silly error code every time I enter any value in size() larger than the image size when I have seen others do it? How do I add the second light so there is no error and I can manipulate the pixels to change the color of the Lights?. I have included my code ,41 lines I think, which I copied bits and pieces of from others. I only wish it was an original. I’m also sorry it looks like blech. I would appreciate any help . Thank You
The way it should work is. Light 1 is at point 0,0 while light two sits at point 150,0. So they sit side by each. If I manually change the color() function, each light should show any color I choose based the RGB manipulation of the pixels
PImage Indicator1, Indicator2;
void setup(){
size(300,127 );
Indicator1 = loadImage(“GreenLight2.jpg”);
image(Indicator1, 0,0);
loadPixels();
Indicator1.loadPixels();
Indicator2 = loadImage(“GreenLight3.jpg”);
image (Indicator2, 150,0);
loadPixels();
Indicator2.loadPixels();
}
void draw() {
for (int x= 0; x < width; x++){
for (int y =0; y < height; y++){
int loc = x+y*width;
float r = red(Indicator1.pixels[loc]);
float g = green(Indicator1.pixels[loc]);
float b = blue(Indicator1.pixels[loc]);
Indicator1.pixels[loc] = color(g,g,b);
}
}
updatePixels();
for (int xx= 0; xx < width; xx++){
for (int yy =0; yy < height; yy++){
int loc1 = xx+yy*width;
float rr = red(Indicator2.pixels[loc1]);
float gg = green(Indicator2.pixels[loc1]);
float bb = blue(Indicator2.pixels[loc1]);
pixels[loc1] = color(rr,gg,bb);
}
}
updatePixels();
}