Creates a new Spectrum. Accepts any arguments that RS.Math.Spectrum#set accepts.
Name | Type | Description |
---|---|---|
initial |
RS.Math.Spectrum | RS.Math.Color | Array | Object | Number |
optional
initial value. |
Example
let s = new RS.Math.Spectrum();
s = new RS.Math.Spectrum(1,0.5,0.7);
s = new RS.Math.Spectrum([0.2,0.3,0.5]);
s = new RS.Math.Spectrum({r: 0.1, r: 0.53, b: 0.2});
s = new RS.Math.Spectrum(new RS.Math.Spectrum([0.2,0.7,0.5]);
Members
-
A 3 element
Array
containing the components of the Spectrum
Methods
-
add (rhs)RS.Math.Spectrum
-
Adds another spectrum to this spectrum.
Name Type Description rhs
RS.Math.Spectrum the other spectrum
Returns:
Type Description RS.Math.Spectrum this Example
const spec = new RS.Math.Spectrum(0.2,0.2,0.3); spec.add(new RS.Math.Spectrum(0.3,0,0.1)); // spec.c is now [0.5,0.2,0.4]
-
Returns the intensity of the components, weighted according to the CIE standard.
Returns:
Type Description Number the intensity -
clone ()RS.Math.Spectrum
-
returns a copy of this spectrum.
Returns:
Type Description RS.Math.Spectrum -
Returns whether this spectrum is equal to another spectrum.
Name Type Description rhs
RS.Math.Spectrum the spectrum to compare to
tolerance
Number optional if provided then this level of tolerance is used.
Returns:
Type Description Boolean true
if equal,false
if notExample
let spec = new RS.Math.Spectrum(0.01,0.05,0.03); spec.equal(spec); // returns true spec.equal(new RS.Math.Spectrum(0.02,0.05,0.03)); // returns false spec.equal(new RS.Math.Spectrum(0.02,0.05,0.03),0.1); // returns true due to tolerance
-
Returns whether this spectrum is equal to another spectrum within a tolerance.
Name Type Description rhs
RS.Math.Spectrum the spectrum to compare to
tolerance
Number optional if provided then this level of tolerance is used, otherwise tolerance is
10e-5
Returns:
Type Description Boolean true
if equal,false
if notExample
let spec = new RS.Math.Spectrum(0.01,0.05,0.03); spec.equal_with_tolerance(spec); // returns true spec.equal_with_tolerance(new RS.Math.Spectrum(0.02,0.05,0.03)); // returns false spec.equal_with_tolerance(new RS.Math.Spectrum(0.01001,0.05,0.03)); // returns true due to default tolerance spec.equal_with_tolerance(new RS.Math.Spectrum(0.02,0.05,0.03),0.1); // returns true due to tolerance
-
gamma_correct (factor)RS.Math.Spectrum
-
Returns a gamma corrected copy of this spectrum. Equivalent to
this ^ (1/factor)
Name Type Description factor
Number the gamma factor
Returns:
Type Description RS.Math.Spectrum the gamma corrected spectrum -
Checks if the spectrum is black.
Name Type Description tolerance.
Number optional A Number used to approximate the comparison.
Returns:
Type Description Boolean true
if black,false
if not -
Returns the intensity of the components, equally weighted.
Returns:
Type Description Number the intensity -
Returns the intensity of the components, weighted according to the NTSC standard.
Returns:
Type Description Number the intensity -
scale (scale)RS.Math.Color
-
Uniformly scales this spectrum.
Name Type Description scale
Number the scaling factor
Returns:
Type Description RS.Math.Color this Example
const spec = new RS.Math.Spectrum(1,0.5,0.6); spec.scale(0.5); // spec.c is now [0.5,0.25,0.3]
-
Sets this spectrum. The source may be of the following types:
- RS.Math.Spectrum
- RS.Math.Color
- an
Array
with 3 or more members - individual arguments for elements 0, 1 and 2.
In the case of an object being supplied it should have the members
r
,g
andb
Parsing failures on any element will set it to 0.Name Type Description source
RS.Math.Color | RS.Math.Spectrum | Array | Object | Number the object to set from or a set of numbers.
Example
const c = new RS.Math.Color(); c.set(1,0.5,0.7); c.set([0.2,0.3,0.5]); c.set({r: 0.1, r: 0.53, b: 0.2}); c.set(new RS.Math.Spectrum([0.2,0.7,0.5]);
-
subtract (rhs)RS.Math.Spectrum
-
Subtracts another spectrum from this spectrum.
Name Type Description rhs
RS.Math.Spectrum the other spectrum
Returns:
Type Description RS.Math.Spectrum this Example
const spec = new RS.Math.Spectrum(0.2,0.2,0.3); spec.subtract(new RS.Math.Spectrum(0.1,0,0.1)); // spec.c is now [0.1,0.2,0.2]
-
tint (rhs)RS.Math.Spectrum
-
Tints this spectrum by another.
Name Type Description rhs
RS.Math.Spectrum the spectrum to tint with
Returns:
Type Description RS.Math.Spectrum this Example
const spec = new RS.Math.Spectrum(0.8,0.8,0.8); spec.tint(new RS.Math.Spectrum(1,0.5,0.6)); // spec.c is now [0.8,0.4,0.48]
-
Returns a string describing this Object.
Returns:
Type Description String A String describing this Object.