douxianliu6756 2019-07-27 19:32
浏览 26

径向渐变带

I generate a radial gradient with this code:

func GenerateGradient(center ds.Coord, radius int, dMethod string) *[]GradientRecord {
var r []GradientRecord
for y := center.Y - radius; y <= center.Y+radius; y++ {
    for x := center.X - radius; x <= center.X+radius; x++ {
        d := float64(DCalc(center, ds.Coord{X: x, Y: y}, dMethod))
        p := ds.Coord{X: x, Y: y}
        var v float64
        v = Lerp(float64(radius), d, 1)
        record := GradientRecord{Point: p.Wrap("t"), Value: v}
        r = append(r, record)
    }
}
return &r

}

DCalc is using the Euclidean distance.

Producing this:

enter image description here

As you can see, it's smooth. But I want the gradient to finish where the radious, so in the Lerp line I change it to:

    v = 1 - Lerp(float64(radius), d/float64(radius), 1)

Producing this:

enter image description here

As you can see there is a cross shaped banding. Wonder if there is a way to remove it? I actually do not need to generate an image, just a smooth gradient transition array for other stuff. I made a picture to expain better the issue..

Thanks!

func Lerp(v0, v1, t float64) float64 {
return (1-t)*v0 + t*v1

}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大