Class: CrystalCell::Povray::Color

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalcell/povray/color.rb

Constant Summary collapse

PI =
Math::PI

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeColor

Returns a new instance of Color.



11
12
# File 'lib/crystalcell/povray/color.rb', line 11

def initialize()
end

Class Method Details

.circle_color(theta) ⇒ Object

色相環(color circle) 上での色を、与えられた角度に対して返す。強度は [r, g, b] の配列で、0.0<=x<=1.0 の実数。



16
17
18
19
20
21
22
23
# File 'lib/crystalcell/povray/color.rb', line 16

def self.circle_color(theta)
  theta = theta % (2*PI); #-2*pi 〜 +2*pi の範囲に入る

  r = self.trapezoidal_wave(theta, (4.0/6.0) * 2.0 * PI)
  g = self.trapezoidal_wave(theta, (0.0/6.0) * 2.0 * PI)
  b = self.trapezoidal_wave(theta, (2.0/6.0) * 2.0 * PI)
  [r, g, b]
end

.trapezoidal_wave(theta, phase) ⇒ Object

台形波



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/crystalcell/povray/color.rb', line 26

def self.trapezoidal_wave(theta, phase)
  x = (theta - phase)/ (2.0*PI)
  x = x -  x.floor
  if (0.0/6.0) <= x && x < (1.0/6.0)
    return x * 6.0
  elsif (1.0/6.0) <= x && x < (3.0/6.0)
    return 1.0
  elsif (3.0/6.0) <= x && x < (4.0/6.0)
    return 4.0 - x * 6.0
  elsif (4.0/6.0) <= x && x < (6.0/6.0)
    return 0.0
  end
end