-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlanetSystem.cs
More file actions
214 lines (164 loc) · 6.94 KB
/
Copy pathPlanetSystem.cs
File metadata and controls
214 lines (164 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
using System;
using OpenTK;
using OpenTK.Mathematics;
using AshLib;
class PlanetSystem{
List<Particle> bodies;
double starMass;
int lastPlanet;
string name;
public PlanetSystem(float starRadius, string starColor){
bodies = new List<Particle>();
bodies.Add(new Particle(new Vector2(0f, 0f), starRadius, new Color3(starColor)));
starMass = bodies[0].mass;
}
public PlanetSystem(float starRadius, float sm, string starColor){
bodies = new List<Particle>();
bodies.Add(new Particle(new Vector2(0f, 0f), new Vector2(0f, 0f), starRadius, sm, new Color3(starColor)));
starMass = bodies[0].mass;
}
public static PlanetSystem Random{get{
Random r = new Random();
float s = random(r, 800f, 2000f);
PlanetSystem p = new PlanetSystem(s, new Color3((byte) (150 + r.Next(106)), (byte) r.Next(256), 0).ToString());
p.setLastName(generateStarName(r));
int n = 1 + r.Next(12);
float d = s * 4f;
for(int i = 0; i < n; i++){
float c = random(r, 1200f + 500f * i, 1150f * i * i + 2000f);
d += c;
float a = random(r, -0.24f * i * i + 2.9f * i + 3f, -2.7f * i * i + 35.7f * i + 4f);
p.addPlanet(a, d, new Color3((byte) (20 + r.Next(235)), (byte) (r.Next(210)), (byte) (r.Next(200))).ToString());
string pname = generatePlanetName(r);
p.setLastName(pname);
if(i > 3 && r.Next(n - i) == 0){
int m = 1 + r.Next(3);
float e = 300f;
float g = (float) p.bodies[i + 1].radius;
for(int j = 0; j < m; j++){
float f = random(r, 20f * i + 100f, 100f * i + 1000f);
e += f;
float b = random(r, g/20f, g/4f);
p.addMoon(b, e, new Color3((byte) (101 + r.Next(155)), (byte) (101 + r.Next(155)), (byte) (101 + r.Next(155))).ToString());
p.setLastName(pname + " " + toRomanNumeral(j + 1));
}
d += 180f * a;
}
}
return p;
}}
static float random(Random r, float min, float max){
return (float) r.NextDouble() * (max - min) + min;
}
public PlanetSystem setName(string n){
name = n;
return this;
}
public PlanetSystem addPlanet(float radius, float distance, string color){
float v = (float) (Math.Sqrt(starMass/distance));
bodies.Add(new Particle(new Vector2(distance, 0f), new Vector2(0f, -v), radius, new Color3(color)));
lastPlanet = bodies.Count - 2;
return this;
}
public PlanetSystem addPlanet(float radius, float mass, float distance, string color){
float v = (float) (Math.Sqrt(starMass/distance));
bodies.Add(new Particle(new Vector2(distance, 0f), new Vector2(0f, -v), radius, mass, new Color3(color)));
lastPlanet = bodies.Count - 2;
return this;
}
public PlanetSystem addMoon(int body, float radius, float distance, string color){
if(body < -1 || bodies.Count <= body + 1){
return this;
}
float v = (float) Math.Sqrt(bodies[body + 1].mass/distance);
bodies.Add(new Particle(bodies[body + 1].position + new Vector2(distance, 0f), bodies[body + 1].velocity + new Vector2(0f, -v), radius, new Color3(color)));
return this;
}
public PlanetSystem addMoon(float radius, float distance, string color){
return addMoon(lastPlanet, radius, distance, color);
}
public PlanetSystem addMoon(int body, float radius, float mass, float distance, string color){
if(body < -1 || bodies.Count <= body + 1){
return this;
}
float v = (float) Math.Sqrt(bodies[body + 1].mass/distance);
bodies.Add(new Particle(bodies[body + 1].position + new Vector2(distance, 0f), bodies[body + 1].velocity + new Vector2(0f, -v), radius, mass, new Color3(color)));
return this;
}
public PlanetSystem addMoon(float radius, float mass, float distance, string color){
return addMoon(lastPlanet, radius, mass, distance, color);
}
private static readonly string[] prefixes = { "Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta", "Theta", "Iota", "Kappa", "Omega", "Septa", "Hikta" };
private static readonly string[] suffixes = { "Majoris", "Minoris", "Centauri", "Eridani", "Cygni", "Draconis", "Andromedae", "Aquarii", "Pegasi", "Serpentis", "Nexis", "Tulkis" };
// Syllables to create original names
private static readonly string[] syllables = { "ael", "ion", "ara", "nus", "zor", "ith", "mir", "phe", "rax", "tor", "xan", "cel", "ven", "tis", "ryn", "ora", "ban", "nam", "iet", "onis" };
private static string generateStarName(Random r){
string name;
// Randomly decide whether to use a traditional prefix or go fully original
bool useTraditional = r.Next(0, 2) == 0;
if (useTraditional)
{
string prefix = prefixes[r.Next(prefixes.Length)];
string suffix = suffixes[r.Next(suffixes.Length)];
name = $"{prefix} {suffix}";
}
else
{
// Generate a random original name from syllables
int syllableCount = r.Next(2, 4); // Between 2 and 3 syllables
name = string.Empty;
for (int i = 0; i < syllableCount; i++)
{
name += syllables[r.Next(syllables.Length)];
}
// Capitalize the first letter
name = char.ToUpper(name[0]) + name.Substring(1);
}
return name;
}
private static readonly string[] descriptors = { "Prime", "Nova", "Minor", "Major", "Alpha", "Beta", "Gamma", "Zeta", "First", "Far", "Delta" };
// Syllables for creating unique planet names
private static readonly string[] psyllables = { "vul", "tora", "mel", "dra", "zan", "nor", "phy", "sel", "kur", "lyra", "os", "ina", "quar", "ven", "tari", "lum", "kep", "nim", "chus", "pol", "sec", "lum", "cus", "kom", "gol", "zont", "lim" };
private static string generatePlanetName(Random r)
{
string name;
// Randomly decide whether to use a descriptor or go fully original
bool useDescriptor = r.Next(0, 2) == 0;
if (useDescriptor)
{
string descriptor = descriptors[r.Next(descriptors.Length)];
name = $"{generateBaseName(r)} {descriptor}";
}
else
{
name = generateBaseName(r);
}
return name;
}
private static string toRomanNumeral(int number)
{
string[] romanNumerals = { "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X" };
return romanNumerals[number - 1];
}
private static string generateBaseName(Random r){
// Generate a random original name from syllables
int syllableCount = r.Next(2, 4); // Between 2 and 3 syllables
string baseName = string.Empty;
for (int i = 0; i < syllableCount; i++)
{
baseName += psyllables[r.Next(psyllables.Length)];
}
// Capitalize the first letter
return char.ToUpper(baseName[0]) + baseName.Substring(1);
}
public PlanetSystem setLastName(string n){
bodies[bodies.Count - 1].setName(n);
return this;
}
public Scene getScene(){
return new Scene(bodies, null, (name == null ? bodies[0].name + " system" : name));
}
public static implicit operator Scene (PlanetSystem a){
return a.getScene();
}
}