Applies a gradient over an array of elements.