生成径向梯度的算法
我这里有这个算法:
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))
生成点对点线性梯度。它对我来说非常有效。我想知道是否有类似的算法来生成径向渐变。我所说的相似是指求解点 P 处的颜色,而不是求解某种颜色处的 P(其中 P 是您正在绘制的坐标)。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 atan2(dy,dx) 上线性上升,其中 dx 是 x 中心,dy 是 y 中心。
这个算法的问题是 ang 实际上是错误的,应该按 pi 旋转并在 0 到 2pi 之间标准化。
Linerise over atan2(dy,dx) where dx is x-center, and dy is y-center.
Problem whit this algorhitm is that ang is actualy wrong and should be rotated by pi and normalized between 0 and 2pi.
根据评论,您想要的仍然可以被视为线性渐变 - 即您有一条从圆的中心到外部的线,并且沿着该线有一个线性渐变。因此,计算结果实际上与您已有的计算结果相同。
编辑:好吧,显然我误解了你想要的。要计算围绕半径运行的梯度,您基本上仍然将其线性化 - 计算出该半径处的周长 (2*Pi*R),然后沿该长度的线进行线性插值。
Based on the comment, what you want can still be viewed as a linear gradient -- i.e. you have a line from the center to the outside of the circle, and you have a linear gradient along that line. As such, the calculation is virtually identical to what you already had.
Edit: Okay, apparently I misunderstood what you want. To figure a gradient running around a radius, you still basically linearize it -- figure out the circumference at that radius (2*Pi*R), and then do a linear interpolation along a line of that length.