MattyUK

03-08-2010, 03:00 AM

I could use some starting pointers for a function I am about to start.

I need to feed RGB values to a graph class. I will need the colors to be different enough so I have settled on a range of numbers with enough visual difference between the resulting colors. I plan to write a function that every time it is run simply returns the next combination of RGB values from the ranges given. This way it will cycle through all possible colors each time it is called within the script.

Lets say I hard code this range:

array(205,155,105);

Then it'd return a single array with the values below for each time it is ran:

array(205,205,205);//1st time function ran AAA

array(205,205,155);//2nd time function ran AAB

array(205,205,105);//3rd time function ran AAC

array(205,155,205);//ABA

array(205,155,155);//5th time function ran ABB

array(205,155,105);//ABC

array(205,105,205);//ACA

array(205,105,155);//ACB

array(205,105,105);//ACC

array(155,205,205);//10th time function ran BAA

array(155,205,155);//BAB

array(155,205,105);//BAC

array(155,155,205);//BBA

array(155,155,155);//BBB

array(155,155,105);//11th time function ran BBC

//and so on

Until all possible combinations have been exhausted, at which point it starts again at the beginning.

I need the function to support any number of ranges (may be more than 3).

So I was thinking of these approaches.

I could use a global variable or session variable to store a count of the last combination returned. Session isn't necessary but might be nice to continue across the page loads.

I could count the hard coded ranges array then if I could somehow put a variable into that math base (say base 3 for the example) I could simply increment it and use that as a pointer to which array variable to output. But I'm not familiar with PHP's math functions.

So in conclusion, I'm not really sure where to start. Can anyone help with some pointers please. I get the feeling it could be a lot easier than I anticipate once I'm latched onto the right approach.

Matt

I need to feed RGB values to a graph class. I will need the colors to be different enough so I have settled on a range of numbers with enough visual difference between the resulting colors. I plan to write a function that every time it is run simply returns the next combination of RGB values from the ranges given. This way it will cycle through all possible colors each time it is called within the script.

Lets say I hard code this range:

array(205,155,105);

Then it'd return a single array with the values below for each time it is ran:

array(205,205,205);//1st time function ran AAA

array(205,205,155);//2nd time function ran AAB

array(205,205,105);//3rd time function ran AAC

array(205,155,205);//ABA

array(205,155,155);//5th time function ran ABB

array(205,155,105);//ABC

array(205,105,205);//ACA

array(205,105,155);//ACB

array(205,105,105);//ACC

array(155,205,205);//10th time function ran BAA

array(155,205,155);//BAB

array(155,205,105);//BAC

array(155,155,205);//BBA

array(155,155,155);//BBB

array(155,155,105);//11th time function ran BBC

//and so on

Until all possible combinations have been exhausted, at which point it starts again at the beginning.

I need the function to support any number of ranges (may be more than 3).

So I was thinking of these approaches.

I could use a global variable or session variable to store a count of the last combination returned. Session isn't necessary but might be nice to continue across the page loads.

I could count the hard coded ranges array then if I could somehow put a variable into that math base (say base 3 for the example) I could simply increment it and use that as a pointer to which array variable to output. But I'm not familiar with PHP's math functions.

So in conclusion, I'm not really sure where to start. Can anyone help with some pointers please. I get the feeling it could be a lot easier than I anticipate once I'm latched onto the right approach.

Matt