Exemple #1
0
        /*  TEMPRGB  --  Calculate the relative R, G, and B components for  a
         *  black	body  emitting	light  at a given temperature.
         *  The Planck radiation equation is solved directly  for
         *  the R, G, and B wavelengths defined for the CIE  1931
         *  Standard    Colorimetric    Observer.	  The	colour
         *  temperature is specified in degrees Kelvin. */

        RGB TempRGB(double temp)
        {
            // Lambda is the wavelength in microns: 5500 angstroms is 0.55 microns.

            double r = Planck(temp, 0.7000);
            double g = Planck(temp, 0.5461);
            double b = Planck(temp, 0.4358);

            RGB rgb = new RGB(r, g, b);

            rgb.Divide(rgb.Max);
            return(rgb);
        }
Exemple #2
0
        public Pixel Generate()
        {
            const double starQuality   = 0.5; // Brightness distribution exponent
            const double starIntensity = 8;   // Brightness scale factor
            const double starTintExp   = 0.5; // Tint distribution exponent

            if ((_random.Next() % 1000) < _starFraction)
            {
                double v = starIntensity * Math.Pow(1 / (1 - Cast(0, 0.9999)),
                                                    starQuality);
                if (v > 255)
                {
                    v = 255;
                }

                /* We make a special case for star colour  of zero in order to
                 * prevent  floating  point  roundoff  which  would  otherwise
                 * result  in  more  than  256 star colours.  We can guarantee
                 * that if you specify no star colour, you never get more than
                 * 256 shades in the image. */

                if (_starColour == 0)
                {
                    return(new Pixel((byte)v, (byte)v, (byte)v));
                }
                else
                {
                    double temp = 5500 + _starColour *
                                  Math.Pow(1 / (1 - Cast(0, 0.9999)), starTintExp) *
                                  (((_random.Next() & 7) != 0) ? -1 : 1);

                    /* Constrain temperature to a reasonable value: >= 2600K
                     * (S Cephei/R Andromedae), <= 28,000 (Spica). */
                    temp = Math.Max(2600, Math.Min(28000, temp));
                    RGB rgb = TempRGB(temp);

                    rgb.Multiply(v);
                    rgb.Add(new RGB(0.499, 0.499, 0.499));
                    rgb.Divide(255);

                    return(new Pixel(rgb.Bytes));
                }
            }
            else
            {
                return(new Pixel(3));
            }
        }
Exemple #3
0
        /*  TEMPRGB  --  Calculate the relative R, G, and B components for  a
        black	body  emitting	light  at a given temperature.
        The Planck radiation equation is solved directly  for
        the R, G, and B wavelengths defined for the CIE  1931
        Standard    Colorimetric    Observer.	  The	colour
        temperature is specified in degrees Kelvin. */
        RGB TempRGB(double temp)
        {
            // Lambda is the wavelength in microns: 5500 angstroms is 0.55 microns.

              double r = Planck(temp, 0.7000);
              double g = Planck(temp, 0.5461);
              double b = Planck(temp, 0.4358);

              RGB rgb = new RGB(r, g, b);
              rgb.Divide(rgb.Max);
              return rgb;
        }