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:
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:
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
}