Question : Fill an array with smooth sequence of colours

Hi
 I wish to populate the elements of an array (of arbitrary length) with a smooth progression of colour values. Using 'BlendColors' I can find a midway colour between two values. What i would like is a neat algorithm to fill each of these intermediate values in a given array.
e.g. for an array of length n
the value at index n div 2  (Call it Vi) is BlendColors( colour[0],color[n]...)
then
the value at index [n div 2] div 2 is the result  BlendColors( colour[0], Vi...)
etc.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
 function BlendColors(Color1, Color2: TColor; Opacity: Byte): TColor;
var
  r, g, b: Byte;
  c1, c2: PByteArray;
begin
  Color1 := ColorToRGB(Color1);
  Color2 := ColorToRGB(Color2);
  c1 := @Color1;
  c2 := @Color2;

  r := Trunc(c1[0] + (c2[0] - c1[0]) * Opacity / 256);
  g := Trunc(c1[1] + (c2[1] - c1[1]) * Opacity / 256);
  b := Trunc(c1[2] + (c2[2] - c1[2]) * Opacity / 256);

  Result := RGB(r, g, b);
end;

Answer : Fill an array with smooth sequence of colours

Assuming c1[0]=20 and c2[0]=250, Nrow=8 and Ncol=5, the matrix for red calculated by the above code will be the RESULT 1 below.
So, first color c1[0]=20 will appear in cel (1,1) and c2[0] in cel (8,5). Of course, Nrow can be equal to Ncol. Please note first col and first row have the same repeated value.  

If it is required a linear variation in the first row and col, then factor should be:
      factor = ((row-1)+(col-1))/(float)((Nrow-1)+(Ncol-1));
That way, the result matrix, for the same parameters as before, will be as in RESULT 2 below.

Jose

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
RESULT 1 for the red component
----------------------------------------------
        20      20      20      20      20
        20      28      36      44      52
        20      36      52      69      85
        20      44      69      93      118
        20      52      85      118     151
        20      61      102     143     184
        20      69      118     167     217
        20      77      135     192     250 
----------------------------------------------
RESULT 2
        20      40      61      82      103
        40      61      82      103     124
        61      82      103     124     145
        82      103     124     145     166
        103     124     145     166     187
        124     145     166     187     208
        145     166     187     208     229
        166     187     208     229     250  
Random Solutions  
 
programming4us programming4us