Class: Graphics::Cubehelix

Inherits:
Rainbow
  • Object
show all
Defined in:
lib/graphics/rainbows.rb

Overview

Spectrum with linearly increasing brightness

Instance Attribute Summary

Attributes inherited from Rainbow

#cache

Instance Method Summary collapse

Methods inherited from Rainbow

#cache_colors, #clamp, #color, #initialize, #scale

Constructor Details

This class inherits a constructor from Graphics::Rainbow

Instance Method Details

#_color(degree) ⇒ Object

:nodoc:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/graphics/rainbows.rb', line 90

def _color degree # :nodoc:
  d = degree/360.0
  start = 0.5 # Starting position in color space - 0=blue, 1=red, 2=green
  rotations = -1.5 # How many rotations through the rainbow?
  saturation = 1.2
  gamma = 1.0
  fract = d**gamma # Position on the spectrum

  # Amplitude of the helix
  amp = saturation * fract * (1 - fract) / 2.0
  angle = 2*Math::PI*(start/3.0 + 1.0 + rotations*fract)
  # From the CubeHelix Equations
  r = fract + amp * (-0.14861 * Math.cos(angle) + 1.78277 * Math.sin(angle))
  g = fract + amp * (-0.29227 * Math.cos(angle) - 0.90649 * Math.sin(angle))
  b = fract + amp * (1.97294 * Math.cos(angle))

  [(r * 255).round, (g * 255).round, (b * 255).round]
end