The Ray Tracer Challenge: Gradient pattern is not a gradient

Hello @jamis and everyone,

I’ve implemented the gradient pattern as described in the book and it gives me this output:

The code for pattern_at (I’ve renamed it to ColorAt) is the following:

func (gp *GradientPattern) ColorAt(point math.Point) math.Color {
	distance := gp.ColorB.Subtract(gp.ColorA)
	fraction := point.X - gomath.Floor(point.X)

	return gp.ColorA.Add(distance.Mul(fraction))
}

As you can see it is not exactly a gradient, but the output makes sense to me.
Our spheres are centered at 0, 0, 0 in object space and at x = 0 the fraction evaluates to 0, which in turn means that we just return colorA.

But I highly suspect that this function is supposed to return an image of a smooth gradient from A to B.
I’m going mildly insane about this issue and if anyone got any advice I would greatly appreciate that.

Thanks! :slight_smile: