Class: Ra::Material

Inherits:
Object
  • Object
show all
Defined in:
lib/ra/material.rb

Overview

A material is used to define the properties of an object that impact the color applied. For example:

material = Ra::Material.new(
 base: Ra::Color.uniform(0.5),
 ambient: 0.2,
 diffuse: 0.5,
 specular: 0.7,
 shininess: 200,
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base:, ambient: 0.2, diffuse: 0.6, specular: 0.6, shininess: 200) ⇒ Material

Returns a new instance of Material.

Parameters:

  • base (Ra::Color, Ra::Pattern:::Base)
  • ambient (Float) (defaults to: 0.2)

    between 0.0 and 1.0

  • diffuse (Float) (defaults to: 0.6)

    between 0.0 and 1.0

  • specular (Float) (defaults to: 0.6)

    between 0.0 and 1.0

  • shininess (Numeric) (defaults to: 200)


21
22
23
24
25
26
27
# File 'lib/ra/material.rb', line 21

def initialize(base:, ambient: 0.2, diffuse: 0.6, specular: 0.6, shininess: 200)
  @base = base
  @ambient = ambient
  @diffuse = diffuse
  @specular = specular
  @shininess = shininess
end

Instance Attribute Details

#ambientObject

Returns the value of attribute ambient.



14
15
16
# File 'lib/ra/material.rb', line 14

def ambient
  @ambient
end

#baseObject

Returns the value of attribute base.



14
15
16
# File 'lib/ra/material.rb', line 14

def base
  @base
end

#diffuseObject

Returns the value of attribute diffuse.



14
15
16
# File 'lib/ra/material.rb', line 14

def diffuse
  @diffuse
end

#shininessObject

Returns the value of attribute shininess.



14
15
16
# File 'lib/ra/material.rb', line 14

def shininess
  @shininess
end

#specularObject

Returns the value of attribute specular.



14
15
16
# File 'lib/ra/material.rb', line 14

def specular
  @specular
end

Instance Method Details

#color(point:) ⇒ Ra::Color

Parameters:

  • point (Vector)

Returns:



31
32
33
34
35
# File 'lib/ra/material.rb', line 31

def color(point:)
  return base if base.is_a?(Color)

  base.color(point:)
end