Class: Ra::Pattern::Stripes

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

Overview

A stripe pattern that alternates colors using:

colors[⌊point.x⌋]

Instance Method Summary collapse

Constructor Details

#initialize(colors:) ⇒ Stripes

Returns a new instance of Stripes.

Parameters:



10
11
12
13
# File 'lib/ra/pattern/stripes.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
24
# File 'lib/ra/pattern/stripes.rb', line 17

def color(point:)
  count = @colors.count
  u = point[0]
  v = point[1]
  value = (u + v) * (2 * count)

  @colors[value.floor % count]
end