Class: Ra::Pattern::Texture

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

Overview

A texture that can load an AVIF / JPG / PNG / BMP:

colors[⌊point.x⌋]

Instance Method Summary collapse

Constructor Details

#initialize(path:) ⇒ Texture

Returns a new instance of Texture.

Parameters:

  • path (Pathname)


12
13
14
15
# File 'lib/ra/pattern/texture.rb', line 12

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

Instance Method Details

#color(point:) ⇒ Ra::Color

Parameters:

  • point (Array<Numeric,Numeric>)

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

Returns:



19
20
21
22
23
24
25
26
27
# File 'lib/ra/pattern/texture.rb', line 19

def color(point:)
  pixel = pixel(point:)

  Color.new(
    r: Float(pixel[0]) / Color::PRECISION,
    g: Float(pixel[1]) / Color::PRECISION,
    b: Float(pixel[2]) / Color::PRECISION,
  )
end