Ramaraunt1

Untitled

Dec 17th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.68 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. //galaxy basics defined in this equation.
  5. public class Galaxy
  6. {
  7. public static int starCount = 20000;
  8. int numberOfHIIDustClouds = 100;
  9. public static int armCount = 4;
  10. public static int guidePointsPerArm = 20;
  11. public static int angleIncrement = 360 / guidePointsPerArm;
  12. public static int startArmAngle = 0;
  13. public static int armAngleIncrement = 360 / armCount;
  14. public static int distanceIncreaseFromCore = 10;
  15. public static int verticalMaxChange = 10;
  16. public static int totalGuidePoints = guidePointsPerArm * armCount;
  17. public static int seventyFive = 50;
  18. public static int twentyFive = 70;
  19. public static GuidePoint[] guidePointsArray = new GuidePoint[totalGuidePoints];
  20. public bool starsMade = false;
  21.  
  22. public static Vector3 center = new Vector3(0, 0, 0);
  23. public static float radius = (float)(distanceIncreaseFromCore + (distanceIncreaseFromCore * guidePointsPerArm) + 20);
  24.  
  25. }
  26.  
  27. public class HIIDustCloud //these bright clouds form on spiral arms, as a result of newly born stars. They have a unique particle and are allways red.
  28. {
  29. float m_temp = 3000;
  30. float m_mag;
  31. Color color = Color.red;
  32. Vector3 m_pos;
  33.  
  34. //default constructor
  35. public HIIDustCloud()
  36. {
  37. m_pos = new Vector3(0, 0, 0);
  38. m_mag = 1;
  39. }
  40. //constructor taking in x,y,and z coordinates
  41. public HIIDustCloud(float x, float y, float z)
  42. {
  43. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  44. float distance = Vector3.Distance(Galaxy.center, m_pos);
  45. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  46. }
  47. //constructor taking in vector3
  48. public HIIDustCloud(Vector3 m_pos)
  49. {
  50. this.m_pos = m_pos; //set the position vector of this star.
  51. float distance = Vector3.Distance(Galaxy.center, this.m_pos);
  52. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  53. }
  54.  
  55. //getters
  56. public float getM_temp()
  57. {
  58. return m_temp;
  59. }
  60. public Color getColor()
  61. {
  62. return color;
  63. }
  64. public Vector3 getM_pos()
  65. {
  66. return m_pos;
  67. }
  68. public float getM_mag()
  69. {
  70. return m_mag;
  71. }
  72.  
  73. //setters
  74. public void setM_temp(float m_temp)
  75. {
  76. this.m_temp = m_temp;
  77. color = calculateColorFromTemp(m_temp);
  78. }
  79. public void setM_pos(Vector3 m_pos)
  80. {
  81. this.m_pos = m_pos;
  82. float distance = Vector3.Distance(Galaxy.center, m_pos);
  83. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  84. }
  85. public void setM_pos(float x, float y, float z)
  86. {
  87. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  88. float distance = Vector3.Distance(Galaxy.center, m_pos);
  89. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  90. }
  91.  
  92. //private methods
  93. private Color calculateColorFromTemp(float temp)
  94. {
  95. //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
  96.  
  97. float calc_temp = temp / 100;
  98. float Red;
  99. float Green;
  100. float Blue;
  101.  
  102. //R
  103. if (calc_temp <= 66)
  104. {
  105. Red = 255;
  106. }
  107. else
  108. {
  109. Red = calc_temp - 60;
  110. Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
  111. if (Red < 0) { Red = 0; }
  112. if (Red > 255) { Red = 255; }
  113. }
  114.  
  115. //G
  116. if (calc_temp <= 66)
  117. {
  118. Green = calc_temp;
  119. Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
  120. if (Green < 0) { Green = 0; }
  121. if (Green > 255) { Green = 255; }
  122. }
  123. else
  124. {
  125. Green = calc_temp - 60;
  126. Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
  127. if (Green < 0) { Green = 0; }
  128. if (Green > 255) { Green = 255; }
  129. }
  130.  
  131. //B
  132. if (calc_temp >= 66)
  133. {
  134. Blue = 255;
  135. }
  136. else if (calc_temp <= 19)
  137. {
  138. Blue = 0;
  139. }
  140. else
  141. {
  142. Blue = calc_temp - 10;
  143. Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
  144. if (Blue < 0) { Blue = 0; }
  145. if (Blue > 255) { Blue = 255; }
  146. }
  147.  
  148. color = new Color(Red, Green, Blue); //finally, create the color and assign it to the variable.
  149. return color;
  150.  
  151. }
  152.  
  153.  
  154. private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
  155. {
  156.  
  157. float brightness;
  158. float percent_distance = distance / Galaxy.radius;
  159. float working_distance = percent_distance * 2;
  160. //this is an exponential decay curve, with brightness as y and working_distance as x.
  161. //at 0, brightness is 1, while at 2, brightness is a little over 0.
  162. brightness = (Mathf.Pow(working_distance, -2));
  163. return brightness;
  164.  
  165. }
  166. }
  167.  
  168. public class Star //These hot balls of fire make up the majority of the galaxy.
  169. {
  170. float m_temp; // star temperature (in kelvin)
  171. float m_mag; // brigtness
  172. Color color; //color
  173. Vector3 m_pos; // current position in cartesion coordinates
  174.  
  175. //default constructor
  176. public Star()
  177. {
  178. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  179. m_mag = 1; //brightness will be highest because star defaults to center of galaxy.
  180. m_pos = new Vector3(0, 0, 0); //star defaults to center of galaxy position.
  181. color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
  182.  
  183. }
  184. //now a constructor with the three vectors (x,y,z) defined
  185. public Star(float x, float y, float z)
  186. {
  187. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  188. color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
  189. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  190. float distance = Vector3.Distance(Galaxy.center, m_pos);
  191. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  192. }
  193. //now a constructor taking in a vector3
  194. public Star(Vector3 m_pos)
  195. {
  196. m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
  197. color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
  198. this.m_pos = m_pos; //set the position vector of this star.
  199. float distance = Vector3.Distance(Galaxy.center, this.m_pos);
  200. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  201. }
  202.  
  203. //getters
  204. public float getM_temp()
  205. {
  206. return m_temp;
  207. }
  208. public Color getColor()
  209. {
  210. return color;
  211. }
  212. public Vector3 getM_pos()
  213. {
  214. return m_pos;
  215. }
  216. public float getM_mag()
  217. {
  218. return m_mag;
  219. }
  220.  
  221. //setters
  222. public void setM_temp(float m_temp)
  223. {
  224. this.m_temp = m_temp;
  225. color = calculateColorFromTemp(m_temp);
  226. }
  227. public void setM_pos(Vector3 m_pos)
  228. {
  229. this.m_pos = m_pos;
  230. float distance = Vector3.Distance(Galaxy.center, m_pos);
  231. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  232. }
  233. public void setM_pos(float x, float y, float z)
  234. {
  235. m_pos = new Vector3(x, y, z); //set the position vector of this star.
  236. float distance = Vector3.Distance(Galaxy.center, m_pos);
  237. m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
  238. }
  239.  
  240.  
  241. //private methods
  242. private Color calculateColorFromTemp(float temp)
  243. {
  244. //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
  245.  
  246. float calc_temp = temp / 100;
  247. float Red;
  248. float Green;
  249. float Blue;
  250.  
  251. //R
  252. if (calc_temp <= 66)
  253. {
  254. Red = 255;
  255. }
  256. else
  257. {
  258. Red = calc_temp - 60;
  259. Red = 329.698727446f * Mathf.Pow(Red, 0.1332047592f);
  260. if (Red < 0) { Red = 0; }
  261. if (Red > 255) { Red = 255; }
  262. }
  263.  
  264. //G
  265. if (calc_temp <= 66)
  266. {
  267. Green = calc_temp;
  268. Green = 99.4708025861f * Mathf.Log(Green) - 161.1195681661f;
  269. if (Green < 0) { Green = 0; }
  270. if (Green > 255) { Green = 255; }
  271. }
  272. else
  273. {
  274. Green = calc_temp - 60;
  275. Green = 288.1221695283f * Mathf.Pow(Green, -0.0755148492f);
  276. if (Green < 0) { Green = 0; }
  277. if (Green > 255) { Green = 255; }
  278. }
  279.  
  280. //B
  281. if (calc_temp >= 66)
  282. {
  283. Blue = 255;
  284. }
  285. else if (calc_temp <= 19)
  286. {
  287. Blue = 0;
  288. }
  289. else
  290. {
  291. Blue = calc_temp - 10;
  292. Blue = 138.5177312231f * Mathf.Log(Blue) - 305.0447927307f;
  293. if (Blue < 0) { Blue = 0; }
  294. if (Blue > 255) { Blue = 255; }
  295. }
  296.  
  297. color = new Color(Red, Green, Blue); //finally, create the color and assign it to the variable.
  298. return color;
  299.  
  300. }
  301.  
  302. private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
  303. {
  304.  
  305. float brightness;
  306. float percent_distance = distance / Galaxy.radius;
  307. float working_distance = percent_distance * 2;
  308. //this is an exponential decay curve, with brightness as y and working_distance as x.
  309. //at 0, brightness is 1, while at 2, brightness is a little over 0.
  310. brightness = (Mathf.Pow(working_distance, -2));
  311. return brightness;
  312.  
  313. }
  314. }
  315.  
  316.  
  317.  
  318. public class GuidePoint
  319. {
  320. //attributes/properties
  321. private Vector3 m_pos;
  322. private int ID;
  323. private static int guide_point_count = -1; //minus 1, cause first guide point is galactic center and has id of -1.
  324. private static Color color = Color.yellow;
  325.  
  326. //constructors
  327. //default constructor
  328. public GuidePoint()
  329. {
  330. m_pos = new Vector3(0, 0, 0);
  331. ID = -4; //ID is -4 (noone)
  332. }
  333. //designated constructor
  334. public GuidePoint(float x_coordinate, float y_coordinate, float z_coordinate)
  335. {
  336. m_pos = new Vector3(x_coordinate, y_coordinate, z_coordinate);
  337. ID = guide_point_count;
  338. guide_point_count++;
  339. }
  340.  
  341. //getters
  342. public Vector3 getM_pos()
  343. {
  344. return m_pos;
  345. }
  346. public int getID()
  347. {
  348. return ID;
  349. }
  350. public int getGuidePointCount()
  351. {
  352. return guide_point_count;
  353. }
  354. public Color getColor()
  355. {
  356. return color;
  357. }
  358.  
  359. //setters
  360. public void setM_pos(Vector3 m_pos)
  361. {
  362. this.m_pos = m_pos;
  363. }
  364. public void setColor(Color new_color)
  365. {
  366. color = new_color;
  367. }
  368.  
  369. //adders
  370. public void addID()
  371. {
  372. ID = guide_point_count;
  373. guide_point_count++;
  374. }
  375. }
  376.  
  377.  
  378. public class galaxygenerationstwo : MonoBehaviour {
  379.  
  380. // Use this for initialization
  381. void Start () {
  382.  
  383. }
  384.  
  385. // Update is called once per frame
  386. void Update () {
  387.  
  388. }
  389. }
Advertisement
Add Comment
Please, Sign In to add comment