Example #1
0
    private System.Drawing.Color ArbitraryRedshiftBasedColor(CoordinateEngine.RelativisticObject dude, CoordinateEngine.RelativisticObject reference)
    {
        //Get z from the two objects
        //for information about z, see http://en.wikipedia.org/wiki/Redshift
        //z==0 means no shift
        //1+z = wavelength(observed)/wavelength(emitted)
        //so multiply the object's wavelength by (1+z)
        //the shift from pure green to pure red or pure blue to pure green is about z=0.17, so this would not be the most dynamic scale for large z
        double z = CoordinateEngine.calculateRedshiftZ(dude, universe.bro);

        //"Accurate" values
        const double upperlimit = 0.17;
        const double lowerlimit = -0.146;

        //Way to "soften" the quick and hard transition between colors.  The 1/exponent roughly multiplies the visible spectrum window...
        z = -1.0 + Math.Pow(1.0 + z, 1.0 / 1.0);

        if (z > upperlimit)//receding fast
        {
            return(System.Drawing.Color.FromArgb(127, 5, 10));
        }
        else if (z < lowerlimit)//approaching fast
        {
            return(System.Drawing.Color.FromArgb(127, 0, 255));
        }
        else if (z > 0.0)
        {
            return(System.Drawing.Color.FromArgb((int)(z / upperlimit * 255), (int)(255 * (1 - z / upperlimit)), 0));
        }
        else  //z<0.0
        {
            return(System.Drawing.Color.FromArgb(0, (int)(255 * (1 - z / lowerlimit)), (int)(z / lowerlimit * 255)));
        }
    }