Better?
300017 Stel Aroba System
Stel Aroba A: class: L4V, absolute magnitude: 18.95, mass: 0.077 xSol. A-B orbit: 23.41 AU, 172.131 yr.
Stel Aroba B: class: M3V, absolute magnitude: 11.02, mass: 0.356 xSol.
Rogue 300017: class: Icy. Rogue planet. temp: 40 K, density: 1.19 xH20, radius: 11639 km, rot: 165d 12h 23m, albedo: 0.51, rings: 18843 km-41663 km.
Stel Aroba Prime: class: Icy. Orbits A (0.047 AU, 13.54 d, 0.007 ecc.). temp: 50 K, density: 1.7 xH20, radius: 15417 km, rot: 324d 23h 8m, albedo: 0.53, rings: 30802 km-75025 km.
Stel Aroba I-b: class: Icey. (orbit: 119482 AU, 2.26 d, 0.007 ecc.) 1.28 xH20, radius: 3486 km, albedo: 0.59.
Stel Aroba I-c: class: Icey. (orbit: 311818 AU, 9.491 d, 0.485 ecc.) 2.59 xH20, radius: 3428 km, albedo: 0.53.
Stel Aroba I-d: class: Icey. (orbit: 481973 AU, 18.382 d, 0.031 ecc.) 2.03 xH20, radius: 1478 km, albedo: 1.
300018 Khelaratz System
Khelaratz A: class: DB6, absolute magnitude: 13.13, mass: 0.625 xSol. A-B orbit: 3.97 AU, 6.683 yr.
Khelaratz B: class: K1V, absolute magnitude: 6.16, mass: 0.776 xSol.
Rogue 300018: class: Methane-Cloud. Rogue planet. temp: 269 K, density: 3.59 xH20, radius: 37861 km, rot: 153d 8h 13m, albedo: 0.46.
Khelaratz Prime: class: Water-Cloud. Orbits A (0.025 AU, 1.87 d, 0 ecc.). temp: 260 K, density: 1.18 xH20, radius: 23848 km, rot: 44d 21h 14m, albedo: 0.81.
Khelaratz I-b: class: Metallic-Silicate. (orbit: 83920.1 AU, 19.734 h, 0.009 ecc.) 4.6 xH20, radius: 4602 km, albedo: 0.23.
Khelaratz I-c: class: Carbon. (orbit: 152717 AU, 2.028 d, 0.005 ecc.) 3.66 xH20, radius: 4350 km, albedo: 0.29.
Khelaratz I-d: class: Silicate. (orbit: 240513 AU, 4.045 d, 0.078 ecc.) 6.16 xH20, radius: 771 km, albedo: 0.297.
Current project: PHP/MySQL star generator
- omega13a
- Posts: 120
- Joined: 15.10.2011
- Age: 40
- With us: 13 years 1 month
- Location: California
- Contact:
Re: Current project: PHP/MySQL star generator
much better
Re: Current project: PHP/MySQL star generator
Anyone have any good data on densities of various star classes? Need to check my work. Also my white dwarfs are too small. < 1000km. LOL
- omega13a
- Posts: 120
- Joined: 15.10.2011
- Age: 40
- With us: 13 years 1 month
- Location: California
- Contact:
Re: Current project: PHP/MySQL star generator
I wrote something in PHP that does that. It uses some code from Celestia and stargen. Here it is:
I think that is all of it (the functions were scattered around in a file with abunch of other unrelated functions. I use it on my website.
Code: Select all
function makeStarTempTable()
{
global $cache;
$cache_name = "star temps";
$temps = $cache->get($cache_name);
if ($temps !== false OR _read('force', TYPE_BOOL, false))
{
return unserialize($temps);
}
$temps = array();
$temps['O'] = makeTable(assignValues( 52500, 52500, 52500, 52500, 48000, 44500, 41000, 38000, 35800, 33000), assignValues(50000, 50000, 50000, 50000, 45500, 42500, 39500, 37000, 34700, 32000), assignValues(47300, 47300, 47300, 47300, 44100, 42500, 39500, 37000, 34700, 32000));
$temps['B'] = makeTable(assignValues( 30000, 25400, 22000, 18700, 17000, 15400, 14000, 13000, 11900, 10500), assignValues(29000, 24000, 20300, 17100, 16000, 15000, 14100, 13200, 12400, 11000), assignValues(26000, 20800, 18500, 16200, 15100, 13600, 13000, 12200, 11200, 10300));
$temps['A'] = makeTable(assignValues( 9520, 9230, 8970, 8720, 8460, 8200, 8020, 7850, 7580, 7390), assignValues(10100, 9480, 9000, 8600, 8300, 8100, 7850, 7650, 7450, 7250), assignValues( 9730, 9230, 9080, 8770, 8610, 8510, 8310, 8150, 7950, 7800));
$temps['F'] = makeTable(assignValues( 7200, 7050, 6890, 6740, 6590, 6440, 6360, 6280, 6200, 6110), assignValues( 7150, 7000, 6870, 6720, 6570, 6470, 6350, 6250, 6150, 6080), assignValues( 7700, 7500, 7350, 7150, 7000, 6900, 6500, 6300, 6100, 5800));
$temps['G'] = makeTable(assignValues( 6030, 5940, 5860, 5830, 5800, 5770, 5700, 5630, 5570, 5410), assignValues( 5850, 5650, 5450, 5350, 5250, 5150, 5050, 5070, 4900, 4820), assignValues( 5550, 5350, 5200, 5050, 4950, 4850, 4750, 4660, 4600, 4500));
$temps['K'] = makeTable(assignValues( 5250, 5080, 4900, 4730, 4590, 4350, 4200, 4060, 3990, 3920), assignValues( 4750, 4600, 4420, 4200, 4000, 3950, 3900, 3850, 3830, 3810), assignValues( 4420, 4330, 4250, 4080, 3950, 3850, 3760, 3700, 3680, 3660));
$temps['M'] = makeTable(assignValues( 3850, 3720, 3580, 3470, 3370, 3240, 3050, 2940, 2640, 2000), assignValues( 3800, 3720, 3620, 3530, 3430, 3330, 3240, 3240, 3240, 3240), assignValues( 3650, 3550, 3450, 3200, 2980, 2800, 2600, 2600, 2600, 2600));
$temps['WN'] = makeTable(assignValues( 50000, 50000, 50000, 50000, 47000, 43000, 39000, 32000, 29000, 29000));
$temps['WC'] = makeTable(assignValues( 60000, 60000, 60000, 60000, 60000, 60000, 60000, 54000, 46000, 38000));
$temps['L'] = makeTable(assignValues( 1960, 1930, 1900, 1850, 1800, 1740, 1680, 1620, 1560, 1500));
$temps['T'] = makeTable(assignValues( 1425, 1350, 1275, 1200, 1140, 1080, 1020, 900, 800, 750));
$temps['WD'] = makeTable(assignValues(100000, 50400, 25200, 16800, 12600, 10080, 8400, 7200, 6300, 5600));
$cache->save(serialize($temps), $cache_name);
return $temps;
}
function assignValues($zero = 0, $one = 0, $two = 0, $three = 0, $four = 0, $five = 0, $six = 0, $seven = 0, $eight = 0, $nine = 0)
{
return array($zero, $one, $two, $three, $four, $five, $six, $seven, $eight, $nine);
}
function makeTable($one, $two = "", $three = "")
{
$table = array();
$table[] = $one;
if (is_array($two))
{
$table[] = $two;
}
if (is_array($three))
{
$table[] = $three;
}
return $table;
}
function getStarRadius($luminosity, $star_type, $star_id)
{
global $mysqli;
if ($star_id != 0)
{
$result = $mysqli->query("SELECT radius FROM stars WHERE id = '".$star_id."'");
if ($result === false)
{
display_mysql_error($mysqli->errno, $mysqli->error);
}
$row = $result->fetch_assoc();
$radius = _type_cast($row['radius'], TYPE_FLOAT);
if ($radius != 0)
{
return $radius;
}
}
if (!defined('STAR_LUMINOSITY'))
{
define('STAR_LUMINOSITY', $luminosity);
}
if (!defined('STAR_TYPE'))
{
define('STAR_TYPE', $star_type);
}
$radius = SOLAR_RADIUS * sqrt($luminosity) * pow2(SOLAR_TEMPERATURE / getStarTemp($star_type));
return $radius;
}
function getStarTemp($star_type)
{
global $cache;
$temps = makeStarTempTable();
$lumIndex = getLumIndex($star_type);
$sub_type = getStarSubType($star_type);
if (substr_count($star_type, "O"))
{
return $temps['O'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "B"))
{
return $temps['B'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "A"))
{
return $temps['A'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "F"))
{
return $temps['F'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "G"))
{
return $temps['G'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "K"))
{
return $temps['K'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "M"))
{
return $temps['M'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "WN"))
{
return $temps['WN'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "WC"))
{
return $temps['WC'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "L"))
{
return $temps['L'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "T"))
{
return $temps['T'][$lumIndex][$sub_type];
}
elseif (substr_count($star_type, "WD"))
{
return $temps['WD'][$lumIndex][$sub_type];
}
return 0;
}
function getLumIndex($star_type)
{
$lumIndex = 0;
if (substr_count($star_type, "Ia0") OR substr_count($star_type, "Ia") OR substr_count($star_type, "Ib") OR substr_count($star_type, "II"))
{
$lumIndex = 2;
}
elseif (substr_count($star_type, "III") OR substr_count($star_type, "IV"))
{
$lumIndex = 1;
}
elseif (substr_count($star_type, "V") OR substr_count($star_type, "VI")) // kind of redundant to have this here but usefull in debuging
{
$lumIndex = 0;
}
return $lumIndex;
}
function getStarSubType($star_type)
{
$sub_type = "";
$sub_type = str_replace("Ia0", "", $star_type);
$sub_type = str_replace("Ia", "", $sub_type);
$sub_type = str_replace("Ib", "", $sub_type);
$sub_type = str_replace("III", "", $sub_type);
$sub_type = str_replace("II", "", $sub_type);
$sub_type = str_replace("VI", "", $sub_type);
$sub_type = str_replace("IV", "", $sub_type);
$sub_type = str_replace("I", "", $sub_type);
$sub_type = str_replace("V", "", $sub_type);
$sub_type = str_replace("O", "", $sub_type);
$sub_type = str_replace("B", "", $sub_type);
$sub_type = str_replace("A", "", $sub_type);
$sub_type = str_replace("F", "", $sub_type);
$sub_type = str_replace("G", "", $sub_type);
$sub_type = str_replace("K", "", $sub_type);
$sub_type = str_replace("M", "", $sub_type);
$sub_type = str_replace("WN", "", $sub_type);
$sub_type = str_replace("WC", "", $sub_type);
$sub_type = str_replace("L", "", $sub_type);
$sub_type = str_replace("T", "", $sub_type);
$sub_type = str_replace("WD", "", $sub_type);
$sub_type = _type_cast($sub_type, TYPE_INT);
return $sub_type;
}
function getStarDensity($radius, $luminosity, $star_type, $star_id = 0)
{
if ($radius == 0)
{
$radius = getStarRadius($luminosity, $star_type, $star_id);
}
return volume_density(_type_cast(getStarMass(), TYPE_FLOAT), $radius);
}
function volume_density($mass, $equat_radius)
{
$mass = $mass * SOLAR_MASS_IN_GRAMS;
$equat_radius = $equat_radius * CM_PER_KM;
$volume = (4.0 * pi() * pow3($equat_radius)) / 3.0;
return $mass / $volume;
}
I think that is all of it (the functions were scattered around in a file with abunch of other unrelated functions. I use it on my website.
Re: Current project: PHP/MySQL star generator
Much prettier than mine. I might use your numbers to adjust mine later, if you don't mind.
Code: Select all
function createstars(){
global $systemid;
global $whichstar;
global $giantskew;
global $blueskew;
$starclassrand = rand(0, 10000000);
$i = 0;
while($i < $blueskew){
$starclassrand = $starclassrand * (rand(0, 100000) / 100000);
$i++; }
$starsubclassrand = rand(0, 9);
$starlumrand = rand(0, 1000000);
$i = 0;
$screwwith = rand( 90000, 110000) / 100000;
$screwwith2 = rand( 70000, 130000) / 100000;
while($i < $giantskew){
$starlumrand = $starlumrand * (rand(0, 100000) / 100000);
$i++; }
if( $starlumrand >= 190000){
$starlumclass = "V";
if($starclassrand > 9000000){ $starclass = "T"; $starcoeff = 0; }
if($starclassrand <= 9000000){ $starclass = "L"; $starcoeff = 0; }
if($starclassrand <= 5000000){ $starclass = "M"; $starcoeff = 10; }
if($starclassrand <= 605000){ $starclass = "K"; $starcoeff = 20; }
if($starclassrand <= 380000){ $starclass = "G"; $starcoeff = 30; }
if($starclassrand <= 150000){ $starclass = "F"; $starcoeff = 40; }
if($starclassrand <= 30000){ $starclass = "A"; $starcoeff = 50; }
if($starclassrand <= 6500){ $starclass = "B"; $starcoeff = 60; }
if($starclassrand <= 30){ $starclass = "O"; $starcoeff = 70; }
if($starclassrand <= 2){ $starclass = "WR"; $starcoeff = 80; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
if($starcoeff <= 10){ $starmass = 0.015 + ($starcoeff / 100); }
else if($starcoeff <= 60 && $starcoeff > 10){ $starmass = 0.115 + (($starcoeff - 10) / 30); }
else if($starcoeff >= 61){ $starmass = 2 + ((rand(10, 50) / 10) * ($starcoeff - 61)); }
$starmass = $starmass * $screwwith;
$capscrewwith1 = rand(400, 460) / 1000;
$capscrewwith2 = rand(1800, 2200) / 1000;
if( $starmass <= $capscrewwith1){ $starlum = pow((0.23 * $starmass), 2.3); }
else if( $starmass > $capscrewwith1 && $starmass < $capscrewwith2){ $starlum = pow($starmass, 4); }
else if( $starmass >= $capscrewwith2){ $starlum = pow($starmass, 3.5); }
if( $starclass == "L"){ $starlum = pow($starmass, 5); }
if( $starclass == "T"){ $starlum = pow($starmass, 7); }
$starlum = $starlum * $screwwith2;
$starclasstotal = $starclass . $starsubclassrand . $starlumclass;
$absmag = 4.83 - (2.5 * log10($starlum)); }
else if( $starlumrand >= 100000 && $starlumrand < 190000){
$starlumclass = "IV";
if($starclassrand > 1210000){ $starclass = "M"; $starcoeff = 10; }
if($starclassrand <= 1210000){ $starclass = "K"; $starcoeff = 20; }
if($starclassrand <= 740000){ $starclass = "G"; $starcoeff = 30; }
if($starclassrand <= 300000){ $starclass = "F"; $starcoeff = 40; }
if($starclassrand <= 60000){ $starclass = "A"; $starcoeff = 50; }
if($starclassrand <= 13000){ $starclass = "B"; $starcoeff = 60; }
if($starclassrand <= 60){ $starclass = "O"; $starcoeff = 70; }
if($starclassrand <= 4){ $starclass = "WR"; $starcoeff = 80; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
if($starcoeff <= 10){ $starmass = 0.1 + ($starcoeff / 100); }
else if($starcoeff <= 60 && $starcoeff > 10){ $starmass = 0.2 + (($starcoeff - 10) / 30); }
else if($starcoeff >= 61){ $starmass = 2 + ((rand(10, 50) / 10) * ($starcoeff - 61)); }
$starmass = $starmass * 1.5;
$starmass = $starmass * $screwwith;
$starlum = pow($starmass, 4);
$starlum = $starlum * $screwwith2;
$starclasstotal = $starclass . $starsubclassrand . $starlumclass;
$absmag = 4.83 - (2.5 * log10($starlum)); }
else if( $starlumrand >= 10000 && $starlumrand < 100000){
$starlumclass = "VII";
if($starclassrand > 2000000){ $starclass = "DA"; $starcoeff = 0; }
if($starclassrand <= 2000000){ $starclass = "DB"; $starcoeff = 10; }
if($starclassrand <= 400000){ $starclass = "DC"; $starcoeff = 20; }
if($starclassrand <= 20000){ $starclass = "DO"; $starcoeff = 30; }
if($starclassrand <= 4000){ $starclass = "DZ"; $starcoeff = 40; }
if($starclassrand <= 200){ $starclass = "DQ"; $starcoeff = 50; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
$starmass = 0.4 + ($starcoeff / 60);
$starmass = $starmass * $screwwith;
$absmag = 15 - ($starmass * 3);
$starclasstotal = $starclass . $starsubclassrand; }
else if( $starlumrand >= 1000 && $starlumrand < 10000){
$starlumclass = "III";
if($starclassrand > 1210000){ $starclass = "M"; $starcoeff = 10; }
if($starclassrand <= 1210000){ $starclass = "K"; $starcoeff = 20; }
if($starclassrand <= 740000){ $starclass = "G"; $starcoeff = 30; }
if($starclassrand <= 300000){ $starclass = "F"; $starcoeff = 40; }
if($starclassrand <= 60000){ $starclass = "A"; $starcoeff = 50; }
if($starclassrand <= 13000){ $starclass = "B"; $starcoeff = 60; }
if($starclassrand <= 60){ $starclass = "O"; $starcoeff = 70; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
$starmass = 1 + ((rand(50, 250) / 40) * ($starcoeff / 70));
$starmass = $starmass * $screwwith;
$magrand = (rand(0, 100) / 50);
if($starcoeff < 45){ $absmag = -2 + (3 * ($starcoeff / 45)) + $magrand; }
if($starcoeff >= 45){ $absmag = 1 - (2 * (45 / $starcoeff)) + $magrand; }
$starclasstotal = $starclass . $starsubclassrand . $starlumclass; }
else if( $starlumrand >= 100 && $starlumrand < 1000){
$starlumclass = "II";
if($starclassrand > 1210000){ $starclass = "M"; $starcoeff = 10; }
if($starclassrand <= 1210000){ $starclass = "K"; $starcoeff = 20; }
if($starclassrand <= 740000){ $starclass = "G"; $starcoeff = 30; }
if($starclassrand <= 300000){ $starclass = "F"; $starcoeff = 40; }
if($starclassrand <= 60000){ $starclass = "A"; $starcoeff = 50; }
if($starclassrand <= 13000){ $starclass = "B"; $starcoeff = 60; }
if($starclassrand <= 60){ $starclass = "O"; $starcoeff = 70; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
$starmass = 5 + ((rand(50, 250) / 10) * ($starcoeff / 70));
$starmass = $starmass * $screwwith;
$magrand = (rand(0, 100) / 50);
if($starcoeff < 45){ $absmag = -3 + $magrand; }
if($starcoeff >= 45){ $absmag = -4 + $magrand; }
$starclasstotal = $starclass . $starsubclassrand . $starlumclass; }
else if( $starlumrand < 100){
if($starclassrand > 1210000){ $starclass = "M"; $starcoeff = 10; }
if($starclassrand <= 1210000){ $starclass = "K"; $starcoeff = 20; }
if($starclassrand <= 740000){ $starclass = "G"; $starcoeff = 30; }
if($starclassrand <= 300000){ $starclass = "F"; $starcoeff = 40; }
if($starclassrand <= 60000){ $starclass = "A"; $starcoeff = 50; }
if($starclassrand <= 13000){ $starclass = "B"; $starcoeff = 60; }
if($starclassrand <= 60){ $starclass = "O"; $starcoeff = 70; }
$starcoeff = $starcoeff + (10 - $starsubclassrand);
$starmass = 5 + ((rand(150, 350) / 5) * ($starcoeff / 70));
$starmass = $starmass * $screwwith;
$magrand = (rand(-100, 100) / 50);
$absmag = -6 + $magrand;
if($absmag >= -6){ $starlumclass = "Ib"; }
else if($absmag <= -6){ $starlumclass = "Ia"; }
$starclasstotal = $starclass . $starsubclassrand . $starlumclass; }
$thisstar = ($systemid * 10) + $whichstar;
$lum = pow(10, ((4.83 - $absmag) / 2.5));
$starmass = round($starmass, 3);
$absmag = round($absmag, 2);
$starcomprand = rand(1, 10) * 2;
if($starcoeff < 30){ $starcomprand = $starcomprand / 2; }
if($starcomprand >= 5){ $starcomp = "S"; }
else if($starcomprand == 4){ $starcomp = "C"; }
else if($starcomprand <= 3){ $starcomp = "L"; }
if($starclass == "WR"){ $startemp = 60000; }
else if($starclass == "O"){ $startemp = 60000 - ($starsubclassrand * 3000); }
else if($starclass == "B"){ $startemp = 30000 - ($starsubclassrand * 2000); }
else if($starclass == "A"){ $startemp = 10000 - ($starsubclassrand * 250); }
else if($starclass == "F"){ $startemp = 7500 - ($starsubclassrand * 150); }
else if($starclass == "G"){ $startemp = 6000 - ($starsubclassrand * 100); }
else if($starclass == "K"){ $startemp = 5000 - ($starsubclassrand * 150); }
else if($starclass == "M"){ $startemp = 3500 - ($starsubclassrand * 100); }
else if($starclass == "L"){ $startemp = 2500 - ($starsubclassrand * 100); }
else if($starclass == "T"){ $startemp = 1500 - ($starsubclassrand * 100); }
else if($starclass == "DO" || $starclass == "DQ"){ $startemp = 60000 - ($starsubclassrand * 1500); }
else if($starclass == "DA"){ $startemp = 45000 - ($starsubclassrand * 1500); }
else if($starclass == "DB"){ $startemp = 30000 - ($starsubclassrand * 2800); }
else if($starclass == "DC"){ $startemp = 12000 - ($starsubclassrand * 300); }
else if($starclass == "DZ"){ $startemp = 9000 - ($starsubclassrand * 300); }
$screwwith = rand( 90000, 110000) / 100000;
$startemp = $startemp * $screwwith;
$stardiam = pow((5800/$startemp), 2) * pow($lum, 0.5); }
- omega13a
- Posts: 120
- Joined: 15.10.2011
- Age: 40
- With us: 13 years 1 month
- Location: California
- Contact:
Re: Current project: PHP/MySQL star generator
Mneme wrote:Much prettier than mine. I might use your numbers to adjust mine later, if you don't mind.
Go ahead. I got the numbers from Celestia.
Re: Current project: PHP/MySQL star generator
How does one do that, precisely?
- omega13a
- Posts: 120
- Joined: 15.10.2011
- Age: 40
- With us: 13 years 1 month
- Location: California
- Contact:
Re: Current project: PHP/MySQL star generator
You download the source code and go through the code. The numbers I got are in src/celengine/star.cpp.
Re: Current project: PHP/MySQL star generator
*grumble* Wish I'd had the brains to think of that rather than trying to pull all the numbers out of my arse...
- PlutonianEmpire
- Posts: 1374
- Joined: 09.09.2004
- Age: 40
- With us: 20 years 3 months
- Location: MinneSNOWta
- Contact:
Re: Current project: PHP/MySQL star generator
You're not alone. I've been there many, many times.Mneme wrote:*grumble* Wish I'd had the brains to think of that rather than trying to pull all the numbers out of my arse...
Terraformed Pluto: Now with New Horizons maps! :D
Re: Current project: PHP/MySQL star generator
4.00 released and I'm taking a break. See Add-On Releases.