RBG LED that I mapped over many colors

Hi, I'm having issues adding more colors to my gradient.
RBG LED that I mapped over many colors, like in the attachment.
I believe my approach is becoming too complicated.

red   = n; 
green = n;
blue  = n;

red  =constrain(red  ,cMid,cMax); //CONSTRAINING VALUES
green=constrain(green,cLow,cMax);
blue =constrain(blue ,cLow,cMid);

red  =map(red  ,cMid,cMax,0  ,255);//MAP VALUES

if(green > cMid)
green=map(green,cMid,cMax,160,0  );
else
green=map(green,cLow,cMid,0  ,160);

blue =map(blue ,cLow,cMid,255,0  );

If someone has another approach which is better I would love to see it.

7540a14bf30374aff0348a51d4678f3fa9a790c2.png

I think I found a solution
http://playground.arduino.cc/Main/MultiMap

I tried to get the multiMap function to work but with strange results.

int rMap[] = {200,1,1,255,255};
int gMap[] = {200,1,255,1,200};
int bMap[] = {255,255,1,1,200};

int r = 10;
int g = 10;
int b = 10;

int cLimits[] ={1500, 12300, 13000, 13500, 14000}; //15`c...30`c...40`c


void setup() {
Serial.begin(9600);
}

void loop() {
 if (Serial.available() > 0) {
int c = Serial.parseInt();

	c = c + 100;       // CONVERT TO AVOID DECIMALS AND NEGATIVES
	c = c * 100; 
//	c  =constrain(c  ,cLimits[0],cLimits[4]);
Serial.println(c);
rgbMap(c);}
}



int rgbMap(int i){

r = multiMap(i, cLimits, rMap, 5);
g = multiMap(i, cLimits, gMap, 5);
b = multiMap(i, cLimits, bMap, 5);

Serial.print("r");Serial.print(r); 
Serial.print(" g");Serial.print(g);
Serial.print(" b");Serial.println(b);
}

int multiMap(int val, int* _in, int* _out, uint8_t size)
{
  // take care the value is within range
  // val = constrain(val, _in[0], _in[size-1]);
  if (val <= _in[0]) return _out[0];
  if (val >= _in[size-1]) return _out[size-1];

  // search right interval
  uint8_t pos = 1;  // _in[0] allready tested
  while(val > _in[pos]) pos++;

  // this will handle all exact "points" in the _in array
  if (val == _in[pos]) return _out[pos];

  // interpolate in the right segment for the rest
  return (val - _in[pos-1]) * (_out[pos] - _out[pos-1]) / (_in[pos] - _in[pos-1]) + _out[pos-1];
}

What I got when I typed in serial 14 trough 41 is

11400
r200 g200 b255
11500
r198 g198 b255
11600
r202 g202 b255
11700
r200 g200 b255
11800
r199 g199 b255
11900
r202 g202 b255
12000
r200 g200 b255
12100
r199 g199 b255
12200
r198 g198 b255
12300
r1 g1 b255
12400
r1 g37 b219
12500
r1 g-20 b276
12600
r1 g16 b240
12700
r1 g-41 b297
12800
r1 g-4 b260
12900
r1 g31 b225
13000
r1 g255 b1
13100
r51 g205 b1
13200
r-28 g284 b1
13300
r22 g234 b1
13400
r-57 g313 b1
13500
r255 g1 b1
13600
r255 g40 b40
13700
r255 g-50 b-50

which definitely isn't the grandient above...

This is a smooth transition from red to yellow to green to cyan to blue.

http://forum.arduino.cc/index.php?topic=372360.msg2567879#msg2567879

You could extend it to continue on from blue to magenta to red.

I used this code, but I wrote 3 quite improper arrays for it, but it sure works.
http://interface.khm.de/index.php/lab/experiments/nonlinear-mapping/

multiMap would have been much better but I just can't get it to work.
Happy hacking everybody!