To generate a gradient between two color
values, you can just linearly interpolate between
them. This will basically work in *any*
color space, although if the transformation
between two color spaces is not linear, the
gradient obtained by linearly interpolating in one
space will not be linear in the other. Thus,
generating gradients in Lab color space is exactly
like generating them in, say, RGB space.

(For color spaces like HSV or HSL which have a
hue coordinate that "loops around", some extra
care may be needed to choose the right direction
to interpolate in; fortunately, you're not asking
about those color spaces here, so I don't need to
go into such details.)

Just as a demonstration, here's how you'd
generate an *n*-sample gradient between the
colors *c1* and *c2* (each given as
a `LabColor`

object with properties
`L`

, `a`

and
`b`

):

```
public static LabColor[]
makeGradient(LabColor c1, LabColor c2, int n) {
LabColor gradient = new LabColor[n];
for (int i = 0; i < n; i++) {
float alpha = (float)i / (n-1); // 0.0
<= alpha <= 1.0
float L = (1-alpha) * c1.L + alpha * c2.L;
float a = (1-alpha) * c1.a + alpha * c2.a;
float b = (1-alpha) * c1.b + alpha * c2.b;
gradient[i] = new LabColor(L, a, b);
}
return gradient;
}
```

This will return a gradient with *n*
color samples, where the first color is equal to
*c1*, the last color is equal to
*c2*, and the rest are interpolated between
them.

However, based on the remark at the end of your
question, I suspect you don't actually
*need* to generate any gradients. Rather,
to find the color in your chart that most closely
matches the one in your sample, you just need to
calculate the perceptual distance of each
chart color from the sample (which, in the Lab
color space, can be well approximated simply by
their Euclidian distance) and select the closest
one:

```
public static LabColor
findNearest(LabColor sample, LabColor[] chart) {
LabColor nearest = null;
float minDistanceSquared =
Float.POSITIVE_INFINITY;
for (int i = 0; i < chart.length; i++) {
float dL = sample.L - chart[i].L;
float da = sample.a - chart[i].a;
float db = sample.b - chart[i].b;
float distanceSquared = dL*dL + da*da +
db*db;
if (distanceSquared <
minDistanceSquared) {
nearest = chart[i];
minDistanceSquared = distanceSquared;
}
}
return nearest;
}
```