I want to make an application that can generate point to point gradient (like Photoshop does). I’m familiar with how to generate an up to down gradient but not point to point. How is this conceptually done.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can’t say if this is exactly how Photoshop does it, or that it’s the most optimal way of doing it, but this should be the basic principle.
Think of the two points as defining a vector. You can find a normal vector for this, which will be perpendicular to the original vector (since that’s the definition of a normal vector).
For each discrete point (pixel) on the line, calculate the gradient color as you would for an up-down (or left-right) gradient of the same length as your vector. Then draw a line of the selected color, such that it passes through the currently chosen point and is parallel with the normal vector.
It’s actually very similar to the approach you’d use for an up-down gradient, except it’s rotated.