It’s funny how knowledge leads to knowledge. You start digging deeper into one thing, and discover threads leading off into related fields. I began by researching maze algorithms, decided I wanted to see what mazes in more complex tesselations would look like, and after one thing or another found myself learning about Wythoff constructions.
The result is Kaleidoscope, a library for generating uniform tilings using Wythoff constructions.
gem install kaleidoscope
A uniform tiling is a tesselation of a plane using regular polygons (with a few other constraints that I won’t go into here). What this means is that, in essense, you give Kaleidoscope a few input parameters, and it hands you a bunch of regular polygons.
1 2 3 4 5 6 7 8 9 10 11
require 'kaleidoscope' pattern = Kaleidoscope::Pattern.new(6, 3) pattern.generate! do |point| point.x * point.x + point.y * point.y < 10 end pattern.polygons.each do |polygon| # ... end
The polygons are generated around the origin of the plane, within a region you specify via the block to the generate! method. Once done, you can translate and scale the polygons to wherever you like, for rendering purposes. Kaleidoscope will even include basic tricoloring data for the polygons, to make it easy to decorate your pattern.
Some obligatory pretty pictures:
The real reason I got into all this, though, was to find interesting tesselations to build mazes in:
It was a fascinating a project, and I had a lot of fun. Oh, and I did it all test-first—a first for me! I learned a ton about TDD.
That said, I’m ready to move on to other projects. I don’t expect I’ll do much more with this library, although there is definitely more that could be done. I’m releasing the code because others might find it interesting. If you do anything nifty with it, let me know!