User Rating 0.0
Total Usage 0 times
Configure settings and click Generate Spectrum
Is this tool helpful?

Your feedback helps us improve.

About

Mapping wavelengths of electromagnetic radiation between 380nm and 780nm to sRGB triplets is a lossy operation. The CIE 1931 color matching functions define the perceptual response, but an sRGB monitor can only reproduce a subset of the visible gamut. This tool applies a simplified spectral-to-RGB algorithm with gamma correction (γ = 0.8) and intensity attenuation at the spectral edges, producing physically-grounded approximations rather than arbitrary rainbow gradients. For custom gradients, linear interpolation operates in RGB space per channel. HSL sweep mode rotates hue from 0° to 360° at constant saturation and lightness, which is useful for perceptual uniformity studies but does not represent physical light. Output dimensions up to 8192 × 8192px are supported. The PNG is generated natively in-browser with lossless compression.

color spectrum png generator gradient creator rainbow spectrum color palette image generator visible light spectrum

Formulas

The visible light spectrum renderer converts wavelength λ to an RGB triplet using a piecewise linear approximation of the CIE response curves.

{
R = 1.0, G = 0, B = 1 λ 380440 380if 380 λ < 440R = 0, G = λ 440490 440, B = 1.0if 440 λ < 490R = 0, G = 1.0, B = 1 λ 490510 490if 490 λ < 510R = λ 510580 510, G = 1.0, B = 0if 510 λ < 580R = 1.0, G = 1 λ 580645 580, B = 0if 580 λ < 645R = 1.0, G = 0, B = 0if 645 λ 780

An intensity factor f attenuates the spectral edges to simulate the eye's reduced sensitivity:

{
f = 0.3 + 0.7 λ 380420 380if 380 λ < 420f = 1.0if 420 λ 700f = 0.3 + 0.7 780 λ780 700if 700 < λ 780

Final pixel value: Rout = round(255 × (R f)γ) where γ = 0.8. For custom gradients, linear interpolation per channel: C(t) = C1 (1 t) + C2 t where t [0, 1].

Where λ = wavelength in nanometers, f = intensity attenuation factor, γ = gamma correction exponent, C1 and C2 = start and end color channel values, t = normalized position along the gradient axis.

Reference Data

ColorWavelength RangeFrequency RangeApprox. sRGB HexPhoton Energy
Violet380 - 450 nm668 - 789 THz#7F00FF2.76 - 3.26 eV
Blue450 - 485 nm618 - 668 THz#0000FF2.56 - 2.76 eV
Cyan485 - 500 nm600 - 618 THz#00FFFF2.48 - 2.56 eV
Green500 - 565 nm530 - 600 THz#00FF002.19 - 2.48 eV
Yellow565 - 590 nm508 - 530 THz#FFFF002.10 - 2.19 eV
Orange590 - 625 nm480 - 508 THz#FF80001.98 - 2.10 eV
Red625 - 780 nm384 - 480 THz#FF00001.59 - 1.98 eV
Near IR (edge)750 - 780 nm384 - 400 THzAttenuated dark red1.59 - 1.65 eV
Near UV (edge)380 - 400 nm749 - 789 THzAttenuated violet3.10 - 3.26 eV
Common Gradient Interpolation Spaces
sRGB LinearChannel-wise lerp in gamma-corrected sRGBFast, simpleCan produce dark midpoints
Linear RGBLerp in linearized (gamma-decoded) spacePhysically accuratePerceptually non-uniform
HSLHue/Saturation/Lightness interpolationPerceptual hue rotationGray midpoints possible
HSVHue/Saturation/Value interpolationSimilar to HSLSlightly different lightness curve
OKLABPerceptually uniform color space (2020)Best perceptual resultsComplex conversion math
PNG Format Details
Bit Depth8 bits per channel (RGBA)32 bppLossless compression
Max DimensionBrowser-dependent, typically 8192 - 16384 pxCanvas limitMemory dependent
Color ProfilesRGB (IEC 61966-2-1)Standard webGamma 2.2

Frequently Asked Questions

The human eye has reduced sensitivity at the extreme ends of the visible spectrum. The tool applies an intensity attenuation factor f that ramps from 0.3 to 1.0 between 380 - 420 nm and from 1.0 to 0.3 between 700 - 780 nm. This models the perceptual falloff at spectral boundaries. Removing this attenuation would produce unrealistically bright extremes that no physical light source produces at those wavelengths.
Visible Spectrum mode maps physical wavelengths (380 - 780 nm) to approximate sRGB values using CIE-derived piecewise functions. The resulting gradient is not perceptually uniform and contains no magenta, because magenta requires simultaneous red and blue stimulation and has no single wavelength. HSL Sweep mode rotates hue from 0° to 360° at fixed saturation and lightness. It includes magenta but does not represent physical light. Choose Visible Spectrum for scientific accuracy and HSL Sweep for design work.
Yes. The output dimensions are independent of your display. You can generate images up to 8192 × 8192 px. The preview canvas scales to fit your viewport, but the downloaded PNG will be the exact pixel dimensions you specify. For print at 300 DPI, a 3000 × 300 px image yields a strip approximately 25 cm wide.
Linear interpolation in sRGB space between complementary colors (e.g., red and cyan) passes through low-saturation midpoints. At t = 0.5, the RGB channels average out, producing a gray or brown. This is a known limitation of RGB-space interpolation. For perceptually cleaner blends between distant hues, use the HSL Sweep mode or add intermediate color stops to steer the gradient through saturated colors.
The visible spectrum mode uses a gamma exponent γ = 0.8 as recommended by Dan Bruton's spectral approximation algorithm. This value slightly boosts brightness to compensate for the piecewise approximation. Custom gradient modes use raw sRGB values with no additional gamma transformation, since input colors are already in gamma-corrected sRGB space.
Orientation changes the mapping axis. In horizontal mode, wavelength or color position maps to the x-axis and each column is a single color. In vertical mode, mapping is along the y-axis and each row is a single color. Diagonal mode maps to the diagonal distance from the top-left corner. The color sequence is identical; only the spatial distribution changes.