Algorithm to generate radial gradient

Posted by user146780 on Stack Overflow See other posts from Stack Overflow or by user146780
Published on 2010-06-09T20:39:15Z Indexed on 2010/06/09 20:42 UTC
Read the original article Hit count: 430

Filed under:
|
|
|

I have this algorithm here:

pc = # the point you are coloring now
p0 = # start point
p1 = # end point
v = p1 - p0
d = Length(v)
v = Normalize(v) # or Scale(v, 1/d)

v0 = pc - p0

t = Dot(v0, v)
t = Clamp(t/d, 0, 1)

color = (start_color * t) + (end_color * (1 - t))

to generate point to point linear gradients. It works very well for me. I was wondering if there was a similar algorithm to generate radial gradients. By similar, I mean one that solves for color at point P rather than solve for P at a certain color (where P is the coordinate you are painting).

Thanks

© Stack Overflow or respective owner

Related posts about c++

Related posts about c