Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- //galaxy basics defined in this equation.
- public class Galaxy
- {
- public static int starCount = 20000;
- int numberOfHIIDustClouds = 100;
- public static int armCount = 4;
- public static int guidePointsPerArm = 20;
- public static int angleIncrement = 360 / guidePointsPerArm;
- public static int startArmAngle = 0;
- public static int armAngleIncrement = 360 / armCount;
- public static int distanceIncreaseFromCore = 10;
- public static int verticalMaxChange = 10;
- public static int totalGuidePoints = guidePointsPerArm * armCount;
- public static int seventyFive = 50;
- public static int twentyFive = 70;
- public static GuidePoint[] guidePointsArray = new GuidePoint[totalGuidePoints];
- public bool starsMade = false;
- public static Vector3 center = new Vector3(0, 0, 0);
- public static float radius = (float)(distanceIncreaseFromCore + (distanceIncreaseFromCore * guidePointsPerArm) + 20);
- }
- 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.
- {
- float m_temp = 3000;
- float m_mag;
- Color color = Color.red;
- Vector3 m_pos;
- //default constructor
- public HIIDustCloud()
- {
- m_pos = new Vector3(0, 0, 0);
- m_mag = 1;
- }
- //constructor taking in x,y,and z coordinates
- public HIIDustCloud(float x, float y, float z)
- {
- m_pos = new Vector3(x, y, z); //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //constructor taking in vector3
- public HIIDustCloud(Vector3 m_pos)
- {
- this.m_pos = m_pos; //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, this.m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //getters
- public float getM_temp()
- {
- return m_temp;
- }
- public Color getColor()
- {
- return color;
- }
- public Vector3 getM_pos()
- {
- return m_pos;
- }
- public float getM_mag()
- {
- return m_mag;
- }
- //setters
- public void setM_temp(float m_temp)
- {
- this.m_temp = m_temp;
- color = calculateColorFromTemp(m_temp);
- }
- public void setM_pos(Vector3 m_pos)
- {
- this.m_pos = m_pos;
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- public void setM_pos(float x, float y, float z)
- {
- m_pos = new Vector3(x, y, z); //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //private methods
- private Color calculateColorFromTemp(float temp)
- {
- //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
- float calc_temp = 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 assign it to the variable.
- return color;
- }
- private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
- {
- float brightness;
- float percent_distance = distance / Galaxy.radius;
- float working_distance = percent_distance * 2;
- //this is an exponential decay curve, with brightness as y and working_distance as x.
- //at 0, brightness is 1, while at 2, brightness is a little over 0.
- brightness = (Mathf.Pow(working_distance, -2));
- return brightness;
- }
- }
- public class Star //These hot balls of fire make up the majority of the galaxy.
- {
- float m_temp; // star temperature (in kelvin)
- float m_mag; // brigtness
- Color color; //color
- Vector3 m_pos; // current position in cartesion coordinates
- //default constructor
- 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.
- color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
- }
- //now a constructor with the three vectors (x,y,z) defined
- public Star(float x, float y, float z)
- {
- m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
- color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
- m_pos = new Vector3(x, y, z); //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //now a constructor taking in a vector3
- public Star(Vector3 m_pos)
- {
- m_temp = Random.Range(3000, 9001);//temperature is a random value between 3000 and 9000.
- color = calculateColorFromTemp(m_temp); //color will be calculated based on temperature.
- this.m_pos = m_pos; //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, this.m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //getters
- public float getM_temp()
- {
- return m_temp;
- }
- public Color getColor()
- {
- return color;
- }
- public Vector3 getM_pos()
- {
- return m_pos;
- }
- public float getM_mag()
- {
- return m_mag;
- }
- //setters
- public void setM_temp(float m_temp)
- {
- this.m_temp = m_temp;
- color = calculateColorFromTemp(m_temp);
- }
- public void setM_pos(Vector3 m_pos)
- {
- this.m_pos = m_pos;
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- public void setM_pos(float x, float y, float z)
- {
- m_pos = new Vector3(x, y, z); //set the position vector of this star.
- float distance = Vector3.Distance(Galaxy.center, m_pos);
- m_mag = calculateBrightnessFromDistance(distance); //calculate brightness based on distance from galactic center.
- }
- //private methods
- private Color calculateColorFromTemp(float temp)
- {
- //caculate color from temp using http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
- float calc_temp = 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 assign it to the variable.
- return color;
- }
- private float calculateBrightnessFromDistance(float distance) //with 1 being maximum, 0 being no brightness
- {
- float brightness;
- float percent_distance = distance / Galaxy.radius;
- float working_distance = percent_distance * 2;
- //this is an exponential decay curve, with brightness as y and working_distance as x.
- //at 0, brightness is 1, while at 2, brightness is a little over 0.
- brightness = (Mathf.Pow(working_distance, -2));
- return brightness;
- }
- }
- public class GuidePoint
- {
- //attributes/properties
- private Vector3 m_pos;
- private int ID;
- private static int guide_point_count = -1; //minus 1, cause first guide point is galactic center and has id of -1.
- private static Color color = Color.yellow;
- //constructors
- //default constructor
- public GuidePoint()
- {
- m_pos = new Vector3(0, 0, 0);
- ID = -4; //ID is -4 (noone)
- }
- //designated constructor
- public GuidePoint(float x_coordinate, float y_coordinate, float z_coordinate)
- {
- m_pos = new Vector3(x_coordinate, y_coordinate, z_coordinate);
- ID = guide_point_count;
- guide_point_count++;
- }
- //getters
- public Vector3 getM_pos()
- {
- return m_pos;
- }
- public int getID()
- {
- return ID;
- }
- public int getGuidePointCount()
- {
- return guide_point_count;
- }
- public Color getColor()
- {
- return color;
- }
- //setters
- public void setM_pos(Vector3 m_pos)
- {
- this.m_pos = m_pos;
- }
- public void setColor(Color new_color)
- {
- color = new_color;
- }
- //adders
- public void addID()
- {
- ID = guide_point_count;
- guide_point_count++;
- }
- }
- public class galaxygenerationstwo : MonoBehaviour {
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment