Class: Ra::Pattern::Checkers
Overview
A checkers pattern that alternates colors using:
colors[⌊u * rows⌋ + ⌊v * cols)⌋ % colors.count]
Constant Summary collapse
Instance Method Summary collapse
- #color(point:) ⇒ Ra::Color
-
#initialize(cols: DEFAULT_COLS, rows: DEFAULT_ROWS, colors: DEFAULT_COLORS) ⇒ Checkers
constructor
A new instance of Checkers.
Constructor Details
#initialize(cols: DEFAULT_COLS, rows: DEFAULT_ROWS, colors: DEFAULT_COLORS) ⇒ Checkers
Returns a new instance of Checkers.
19 20 21 22 23 24 |
# File 'lib/ra/pattern/checkers.rb', line 19 def initialize(cols: DEFAULT_COLS, rows: DEFAULT_ROWS, colors: DEFAULT_COLORS) super() @rows = rows @cols = cols @colors = colors end |
Instance Method Details
#color(point:) ⇒ Ra::Color
28 29 30 31 32 33 34 |
# File 'lib/ra/pattern/checkers.rb', line 28 def color(point:) u = point[0] v = point[1] index = (u * @rows).floor + (v * @cols).floor @colors[index % @colors.count] end |