A ring pattern depends on two dimensions, x and z, to decide which color to return. It works similarly to stripes, but instead of testing the distance of the point in just x, it tests the distance of the point in both x and z, which results in this pattern of concentric circles as shown in the figure.
Write the following test for this. You’re checking to make sure that these rings extend in both x and z.
| Scenario: A ring should extend in both x and z |
| Given pattern ← ring_pattern(white, black) |
| Then pattern_at(pattern, point(0, 0, 0)) = white |
| And pattern_at(pattern, point(1, 0, 0)) = black |
| And pattern_at(pattern, point(0, 0, 1)) = black |
| # 0.708 = just slightly more than √2/2 |
| And pattern_at(pattern, point(0.708, 0, 0.708)) = black |
To make that pass, you’ll implement the function for a ring pattern, something like this:
Make that test pass, and then we’ll look at one more pattern: checkers.
3.138.116.20