Search⌘ K
AI Features

Solution: Generating Geometric Masks

Explore how to create geometric masks that shape mazes by using code to mirror octant patterns and link concentric bands. Understand the process of generating masks through parameterized methods to design customized maze layouts.

We'll cover the following...

Solution

Let's execute the following solution code and see how it works:

C++
require 'mask'
require 'chunky_png'
class ConcentricSquaresMask < Mask
def initialize(band_count, band_size)
size = 2 * (band_count * 2 - 1) * band_size
super(size, size)
@mid = size / 2
@mid.times do |i|
block = i / band_size
mirror_octantwise(i, block.even?)
end
# add a narrow bands to link the rings
size.times do |i|
self[@mid, i] = true
self[@mid - 1, i] = true
self[i, @mid] = true
self[i, @mid - 1] = true
end
end
def mirror_octantwise(i, value)
(i + 1).times do |j|
self[@mid - j - 1, @mid - i - 1] = value
self[@mid - i - 1, @mid - j - 1] = value
self[@mid + j, @mid - i - 1] = value
self[@mid + i, @mid - j - 1] = value
self[@mid - j - 1, @mid + i] = value
self[@mid - i - 1, @mid + j] = value
self[@mid + j, @mid + i] = value
self[@mid + i, @mid + j] = value
end
end
end

Code explanation

Lines 4–19: ...