Hi.
At this point i've calculated one color value.
Can i calculate the other values in the same function, "medR_"? Or i've to create 3 different functions?
If i put the return values in a global variable, i can use them to fill forms, right?
---
PImage img;
color [] imageColors;
int medR = 0;
void setup() {
size(533, 750);
background(0);
smooth();
img = loadImage( "almanaque.jpg");
img.loadPixels ();
//New list with colors?
imageColors = new color [img.pixels.length];
// search each line and row of the image
for (int x=0; x < img.width; x++) {
for (int y=0; y < img.height; y++) {
int loc = x + y*img.width;
float r = red (img.pixels [loc]);
float g = green (img.pixels [loc]);
float b = blue (img.pixels [loc]);
imageColors[loc] = color (r, g, b);
}
}
// find average of RGB
medR = medR_(imageColors);
println (medR);
img.updatePixels ();
}
// function to find average of R color
int medR_ (int[] rvalues) {
//total
int totalR = 0;
//cicle through R values
for (int i=0; i < rvalues.length; i++) {
totalR += blue (rvalues[i]);
}
return totalR/rvalues.length;
}
void draw() {
fill (204, 126, 124);
rect (0, 0, width, height);
}