gpt4 book ai didi

c++ - 生成径向梯度的算法

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:25:51 28 4
gpt4 key购买 nike

我这里有这个算法:

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 是您正在绘制的坐标)。

谢谢

最佳答案

//loop through vector
//x and y px position
int x = i%w;
int y = i/w;
float d = distance(center,int2(x,y));
//if within the grad circle
if(d < radius)
{
//somehow set v[i] alpha to this:
float a = d/r;
}

关于c++ - 生成径向梯度的算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3009754/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com