# Day 14, Patterns, patterns, patterns

The more, the merrier, they say, and that probably goes for patterns as well. Stripes got some more company, with gradients, concentric circles, and checkered patterns. And why constrain the number of colors in a pattern?

```
def color_at(point)
g = grade(point)
c = @pigments.count - 1
p = g.floor % c
a, b = @pigments[p..p + 1]
a.interpolate(b, g % 1)
end
```

Most of the work getting the multicolor working was refactoring all the kinds of patterns I created before. Each kind of pattern implements their own version of the `grade`

method, that converts a 3D point to a scalar value, and the the base class takes care of the rest. With that in place, extending patterns to taking other patterns as pigments, instead of just plain colors, should be an easy next step.

*Discrete rings*

```
def grade(point)
Math.sqrt(point.x**2 + point.z**2).floor
end
```

*Linear gradient*

```
def grade(point)
point.x
end
```

## Next related

### Day 15, Patterns all the way down

## Previous related

### Day 13, Big Stripey Lie

### Day 12, Spheres on a plane

Spheres are nice and all, but we need more shapes to make the world go around. So, a little bit of refactoring to get most the juicy bits from spheres apply to every kind of shape, such as planes. So flat, and infinite.

### Day 11, Into the Shadows

After todays work we can render the shadows cast by objects in our scenes!