Day 15, Patterns all the way down
I heard you liked patterns, so how about some patterns within your patterns, so you can pattern while you pattern?
Supporting nesting of the already existing patterns was not that difficult, just make colors respond to #color_at(point)
and make a recursive call in the base class.
def color_at(point)
point = to_local(point)
g = grade(point)
c = @pigments.count - 1
n = g.floor % c
a, b = @pigments[n..n + 1].map { |p| p.color_at(point) }
a.interpolate(b, g % 1)
end
Blending arbitrary patterns with a function is just as easy, so here are the arithmethic, geometric, and quadratic mean blends of the stripy patterns nested in the checkers before. This overrides the #color_at
method completely, and so does the next modifier pattern, as they have no base pattern on their own.
While we’re at it, why not add a simplex noise perturbation as well for organic patterns.
Next related
Day 16, Halfway there
Fitting that the halfway point would be about reflections. Pagewise we’re more than halvway through the book, but I’m guessing that there will be plenty of things to do for the remaining 15 days. There’s still the going back and replacing the homebuilt algebra code with stdlib, if nothing else.
Previous related
Day 14, Patterns, patterns, patterns
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.