###### Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

Deciding to stick with EE.

Mohamed Asif

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
###### Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

# Fill an array with smooth sequence of colours

Algorithms
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.

`````` 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;
``````