Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Star()
- {
- m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
- m_mag = 1; //brightness will be highest because star defaults to center of galaxy.
- m_pos = new Vector3(0, 0, 0); //star defaults to center of galaxy position.
- //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
- float calc_temp = m_temp / 100;
- float Red;
- float Green;
- float Blue;
- //R
- if (calc_temp <= 66)
- {
- Red = 255;
- }
- else
- {
- Red = calc_temp - 60;
- Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
- if (Red < 0) { Red = 0; }
- if (Red > 255) { Red = 255; }
- }
- //G
- if (calc_temp <= 66)
- {
- Green = calc_temp;
- Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
- if (Green < 0) { Green = 0; }
- if (Green > 255) { Green = 255; }
- }
- else
- {
- Green = calc_temp - 60;
- Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
- if (Green < 0) { Green = 0; }
- if (Green > 255) { Green = 255; }
- }
- //B
- if (calc_temp >= 66)
- {
- Blue = 255;
- }
- else if (calc_temp <= 19)
- {
- Blue = 0;
- }
- else
- {
- Blue = calc_temp - 10;
- Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
- if (Blue < 0) { Blue = 0; }
- if (Blue > 255) { Blue = 255; }
- }
- color = new Color(Red, Green, Blue); //finally, create the color and assigne it to the variable.
- }
- //now a constructor with the three vectors (x,y,z) defined
- public Star(float x, float y, float z)
- {
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment