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)); } }