Ramaraunt1

Untitled

Dec 17th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. public Star()
  2. {
  3. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  4. m_mag = 1; //brightness will be highest because star defaults to center of galaxy.
  5. m_pos = new Vector3(0, 0, 0); //star defaults to center of galaxy position.
  6.  
  7. //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
  8.  
  9. float calc_temp = m_temp / 100;
  10. float Red;
  11. float Green;
  12. float Blue;
  13.  
  14. //R
  15. if (calc_temp <= 66)
  16. {
  17. Red = 255;
  18. }
  19. else
  20. {
  21. Red = calc_temp - 60;
  22. Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
  23. if (Red < 0) { Red = 0; }
  24. if (Red > 255) { Red = 255; }
  25. }
  26.  
  27. //G
  28. if (calc_temp <= 66)
  29. {
  30. Green = calc_temp;
  31. Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
  32. if (Green < 0) { Green = 0; }
  33. if (Green > 255) { Green = 255; }
  34. }
  35. else
  36. {
  37. Green = calc_temp - 60;
  38. Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
  39. if (Green < 0) { Green = 0; }
  40. if (Green > 255) { Green = 255; }
  41. }
  42.  
  43. //B
  44. if (calc_temp >= 66)
  45. {
  46. Blue = 255;
  47. }
  48. else if (calc_temp <= 19)
  49. {
  50. Blue = 0;
  51. }
  52. else
  53. {
  54. Blue = calc_temp - 10;
  55. Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
  56. if (Blue < 0) { Blue = 0; }
  57. if (Blue > 255) { Blue = 255; }
  58. }
  59.  
  60. color = new Color(Red, Green, Blue); //finally, create the color and assigne it to the variable.
  61.  
  62. }
  63. //now a constructor with the three vectors (x,y,z) defined
  64. public Star(float x, float y, float z)
  65. {
  66.  
  67. }
  68.  
  69. };
Advertisement
Add Comment
Please, Sign In to add comment