Class: Ra::Pattern::Rings

Inherits:
Base
  • Object
show all
Defined in:
lib/ra/pattern/rings.rb

Overview

A rings pattern that alternates colors using:

colors[⌊√(u² + v²)⌋]

Instance Method Summary collapse

Constructor Details

#initialize(colors:) ⇒ Rings

Returns a new instance of Rings.

Parameters:



10
11
12
13
# File 'lib/ra/pattern/rings.rb', line 10

def initialize(colors:)
  super()
  @colors = colors
end

Instance Method Details

#color(point:) ⇒ Ra::Color

Parameters:

  • point (Vector)

    <u = 0.0..1.0, v = 0.0..1.0>

Returns:



17
18
19
20
21
22
23
# File 'lib/ra/pattern/rings.rb', line 17

def color(point:)
  u = point[0]
  v = point[1]
  index = Math.sqrt((u**2) + (v**2)).floor

  @colors[index % @colors.count]
end