Making a Ring Pattern

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.

images/patterns/rings.png

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:

images/jbmath/patterns.rings.function.png

Make that test pass, and then we’ll look at one more pattern: checkers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.116.20