Math behind Photoshop's gradient tool

312 Views Asked by At

I want to implement something like Photoshop's gradient tool and I need to understand the math behind it. Can anyone explain the differences between linear, radial, angle, reflected, diamond gradients? These give a different shape of gradient:

enter image description here enter image description here enter image description here enter image description here

enter image description here enter image description here

Photoshop's Gradient Tool:
To apply the gradient tool we first choose two colors. Then some algorithm or a mathematical function is applied to each pixel of the image to get a gradient color ranges from the first selected color to the second one. For example, in the first picture above, the colors are going from yellow to black. In all of the others the color is going from white to black.