java.lang.Object
de.grogra.gpuflux.imp3d.spectral.Wavelength
Create a Color object given the wavelength of the colour in nanometers.
instead of: Color c = new Color(255, 0, 0); use the freqency in nanometers, and gamma 0.0. .. 1.0. Color c =
Wavelength.wlColor( 400.0f, 0.80f );
or using frequency in Terahertz and gamma 0.0. .. 1.0. Color c = Wavelength.fColor( 500.0f, 1.0f );
You might use it to draw a realistic rainbow, or to write educational Applets about the light spectrum.
Based on a Fortran program by Dan Bruton (astro@tamu.edu) The original Fortran can be found at:
http://www.isc.tamu.edu/~astro/color.html It uses linear interpolation on ten spectral bands.
This code goes from Waveleng or Terahertz to RGB. It does not currently support going the other way.
There is a theoretical problem with going the other way. Most RGB colours are not pure spectrum colours.
You could go the other way by:
1. creating an exhaustive table of RGB:terahertz pairs using terahertz to convert to RGB.
2. Sort by RGB
3. eliminate RGB duplicates keeping the median/average terahertz value.
4. You do the above once to create the table.
5. An run time, you do a binary search lookup on RGB to find the terahertz value.
If you don't find an exact RGB match, you announce the RGB is impure.
6. You might then search for one-unit off values in RGB + or -, (14 possibilities).
- Since:
- 1998
- Version:
- 1.3 2007-11-27 correct slight error in speed of light.
- Author:
- Roedy Green, Canadian Mind Products
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic final int
color2int
(int red, int green, int blue) Converts a given color represented by its RGB color values to its integer value.static final int
Converts a given color to its integer value.static final Color
fColor
(float freq, float gamma) Creates a Color object given the frequency instead of the usual RGB or HSB values.static final Color
wvColor
(float wl, float gamma) Creates a Color object given the wavelength instead of the usual RGB or HSB values.
-
Constructor Details
-
Wavelength
public Wavelength()
-
-
Method Details
-
fColor
Creates a Color object given the frequency instead of the usual RGB or HSB values.- Parameters:
freq
- frequency of the light in Terahertz (10.0e12 Hz) Will show up black outside the range 384..789 TeraHertz.gamma
- 0.0 .. 1.0 intensity.- Returns:
- Color object of that frequency and intensity.
-
wvColor
Creates a Color object given the wavelength instead of the usual RGB or HSB values.- Parameters:
wl
- wavelength of the light in nanometers. Will show up black outside the range 380..780 nanometers.gamma
- 0.0 .. 1.0 intensity.- Returns:
- Color object with tha tha wavelength and intensity
-
color2int
Converts a given color to its integer value.- Parameters:
c
- color- Returns:
- color as integer 0xFF000000 for 100% Alpha
-
color2int
public static final int color2int(int red, int green, int blue) Converts a given color represented by its RGB color values to its integer value.- Parameters:
red
- channel [0,255] of the default sRGB spacegreen
- channel [0,255] of the default sRGB spaceblue
- channel [0,255] of the default sRGB space- Returns:
- color as integer 0xFF000000 for 100% Alpha
-