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 › get highest value & position in an array ?
Page Index Toggle Pages: 1
get highest value & position in an array ??? (Read 916 times)
get highest value & position in an array ???
Feb 1st, 2010, 7:53am
 
hi,

how can i get the highest stored value and its position in an array??

regards maik
Re: get highest value & position in an array ???
Reply #1 - Feb 1st, 2010, 8:08am
 
Initialize a currMaxVal variable to the lower possible value in your array.
Loop on the array.
If current value is above currMaxVal, set currMaxVal to current value and set maxValPos to current index.
Re: get highest value & position in an array ???
Reply #2 - Feb 2nd, 2010, 10:15am
 
thanks,

that works great.
here... get the strongest band with its value.

and now the next Wink
now i get the bands 0 to 256.
how can i,assign a rgb color to that value??
when 0 is red, and 256 is blue.

regards maik
Re: get highest value & position in an array ???
Reply #3 - Feb 2nd, 2010, 3:59pm
 
I would suggest to look into HSB (see colorMode()), varying the Hue component.
Re: get highest value & position in an array ???
Reply #4 - Feb 3rd, 2010, 7:24am
 
wow ,

that is what i'm locking for Cheesy
works the way i want it Wink

Code:
for(int i = 0; i < rowmax ; i++)
{
sgram2[i] = (int)Math.round(100*fft.getBand(i));
if ((int)Math.round(fft.getBand(i)) > (currMaxVal)){currMaxVal=((int)Math.round(fft.getBand(i)));
maxValPos = i;
}
}
noStroke();
colorMode(HSB, 140);

color a = color(maxValPos, currMaxVal, currMaxVal);


regards maik
Page Index Toggle Pages: 1