<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Walker Solar System Generator</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Metrophobic">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Orbitron">
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Comfortaa">
    <style>
        :root {
            --textcolor: rgb(255,255,255);
            --textcolorb: rgb(255,255,255);    
            --bgcolor: rgb(16,16,16);
            --btncolorpressed: rgb(48,48,48);
            --btncolor: rgb(64,64,64);
            --btncolorhover: rgb(96,96,96);
            --scrollcolor: rgb(96,96,96);
            --insetcolor:rgb(32,32,32);
            --typeg:rgb(255,255,255);
            --typef:#c0e8ff;
            --typek:#fff0c1;
            --yellow: #ffd636;
            --cyan: #51e9f4;
            --lightgreen: #7fed56;
            --typea: #89d4ff;
            --innershadowcolor: #0000004F;
            --innershadowcolorb: #0000001F;
            --borderradiusdf: 15px;
            --whiteiconfilter: none;
            --font: Metrophobic, sans-serif;
            --hfont: Eras BQ, sans-serif;

        }
        [data-theme="light"] {
            --textcolor: rgb(0,0,0);
            --textcolorb: rgb(0,0,0);    
            --bgcolor: rgb(250,250,250);
            --btncolorpressed: rgb(160,160,160);
            --btncolor: rgb(192,192,192);
            --btncolorhover: rgb(240,240,240);
            --scrollcolor: rgb(158, 158, 158);
            --insetcolor:rgb(240,240,240);
            --typek:#beab71;
            --typeg:rgb(140,140,140);
            --typef:rgb(140,150,160);
            --typea: #72aed1;
            --yellow: #b89b29;
            --cyan: #22bac5;
            --lightgreen: #53d822;
            --innershadowcolor: #0000004F;
            --innershadowcolorb: #0000001F;
            --borderradiusdf: 15px;
            --whiteiconfilter: brightness(0);
            --font: Metrophobic, sans-serif;
            --hfont: Eras BQ, sans-serif;
        }
        [data-theme="green"] {
            --textcolor: rgb(255, 255, 255);
            --textcolorb: rgb(255,255,255);    
            --bgcolor: rgb(0, 0, 0);
            --btncolorpressed: rgb(0, 59, 3);
            --btncolor: rgb(0, 83, 4);
            --btncolorhover: rgb(0, 104, 5);
            --scrollcolor: rgb(0, 128, 11);
            --insetcolor:rgb(0, 26, 4);
            --typeg:rgb(255,255,255);
            --typef:#c0e8ff;
            --typek:#fff0c1;
            --yellow: #ffd636;
            --cyan: #51e9f4;
            --lightgreen: #7fed56;
            --typea: #89d4ff;
            --innershadowcolor: #FFFFFF00;
            --innershadowcolorb: #FFFFFF00;
            --borderradiusdf: 0px;
            --whiteiconfilter: none;
            --font: monospace;
            --hfont: Orbitron, sans-serif;
        }
        [data-theme="red"] {
            --textcolor: rgb(255,255,255);
            --textcolorb: rgb(255,255,255);    
            --bgcolor: rgb(15, 0, 0);
            --btncolorpressed: rgb(53, 0, 0);
            --btncolor: rgb(66, 0, 0);
            --btncolorhover: rgb(95, 0, 0);
            --scrollcolor: rgb(99, 0, 0);
            --insetcolor:rgb(41, 0, 0);
            --typeg:rgb(255,255,255);
            --typef:#c0e8ff;
            --typek:#fff0c1;
            --yellow: #ffd636;
            --cyan: #51e9f4;
            --lightgreen: #7fed56;
            --typea: #89d4ff;
            --innershadowcolor: #0000004F;
            --innershadowcolorb: #0000001F;
            --borderradiusdf: 15px;
            --whiteiconfilter: none;
            --font: Metrophobic, sans-serif;
            --hfont: Eras BQ, sans-serif;

        }
        [data-theme="blue"] {
            --textcolor: rgb(255,255,255);
            --textcolorb: rgb(255,255,255);        
            --bgcolor: rgb(0, 0, 19);
            --btncolorpressed: rgb(0, 16, 160);
            --btncolor: rgb(0, 64, 202);
            --btncolorhover: rgb(0, 86, 214);
            --scrollcolor: rgb(0, 38, 141);
            --insetcolor:rgb(0, 8, 41);
            --typeg:rgb(255,255,255);
            --typef:#c0e8ff;
            --typek:#fff0c1;
            --yellow: #ffd636;
            --cyan: #51e9f4;
            --lightgreen: #7fed56;
            --typea: #89d4ff;
            --innershadowcolor: #0084ff1f;
            --innershadowcolorb: #00ccff1f;
            --borderradiusdf: 8px;
            --whiteiconfilter: none;
            --font: Comfortaa, sans-serif;
            --hfont: Comfortaa, sans-serif;


        }
        [data-theme="2048"] {
            --textcolor: #faf8ef;
            --textcolorb: #776e65;
            --bgcolor: #faf8ef;
            --btncolorpressed: #8f7a66;
            --btncolor: #8f7a66;
            --btncolorhover: #8f7a66;
            --scrollcolor: rgb(158, 158, 158);
            --insetcolor:#eee1c9;
            --typek:#beab71;
            --typeg:rgb(140,140,140);
            --typef:rgb(140,150,160);
            --typea: #72aed1;
            --yellow: #b89b29;
            --cyan: #22bac5;
            --lightgreen: #53d822;
            --innershadowcolor: #FFFFFF00;
            --innershadowcolorb: #FFFFFF00;
            --borderradiusdf: 5px;
            --whiteiconfilter: brightness(0);
            --font: sans-serif;
            --hfont: sans-serif;
        }
        [data-theme="midnight"] {
            --textcolor: #ffffff;
            --textcolorb: #ffffff;
            --bgcolor: #000000;
            --btncolorpressed: #000000;
            --btncolor: #000000;
            --btncolorhover: #000000;
            --scrollcolor: rgb(35, 0, 58);
            --insetcolor:#000000;
            --typek:#beab71;
            --typeg:rgb(140,140,140);
            --typef:rgb(140,150,160);
            --typea: #72aed1;
            --yellow: #b89b29;
            --cyan: #22bac5;
            --lightgreen: #53d822;
            --innershadowcolor: #FFFFFF00;
            --innershadowcolorb: #FFFFFF00;
            --borderradiusdf: 5px;
            --whiteiconfilter: none;
            --font: Metrophobic, sans-serif;
            --hfont: Eras BQ, sans-serif;
        }
        p {
            font-family: var(--font);
            font-weight:bold;
            font-size: larger;
            color: var(--textcolorb);
            
        }
        #pagenumber {
            font-family: var(--font);
            font-weight:bold;
            font-size: larger;
            color: var(--textcolor);
            text-align: center;
        }
        .systemcontainer p {
            color: var(--textcolorb);
            vertical-align: middle;
        }
        #pagenumber {
            color: var(--textcolorb);
        }

        .patchnotes {
            text-align: center;
        }

        h3 {
            font-family: var(--font);
            font-weight:bold;
            font-size: x-large;
            color: var(--textcolorb);
        }
        .systemcontainer h3 {
            color: var(--textcolorb);
            vertical-align: middle;
        }

        h1 {
            font-family: var(--hfont);
            color: var(--textcolorb);
            font-size: 50;
            text-align: center;
        }
        .infocontainer h1 {
            font-family: var(--hfont);
            color: var(--textcolorb);
            font-size: 50;
            text-align: center;
        }
        html {
            background-color: var(--bgcolor);
            transition: 0.15s;
        }
        body {
            width: 80%;
            margin-left: 20%;
            overflow-y: scroll;
            overflow-x: scroll;
            margin-right: 0px;
            
        }
        .main {
            width: 92%;
            margin: auto;
            
            left:25%;
            height:auto;
            overflow-x: scroll;
            overflow-y: scroll;
        }
        hr{
            color:var(--textcolor);
            border-color:var(--textcolor);

        }
        .systemcontainer hr {
            border-color: var(--textcolor);
        }
        .genbutton {
            background: var(--btncolor);
            padding:10px;
            padding-right:15px;
            padding-left:15px;
            display: block;
            margin: auto;
            width:80%;
            font-family: var(--font);
            font-weight:bold;
            font-size: 1.25em;
            color: var(--textcolor);
            border: 0px;
            border-radius: var(--borderradiusdf);
            cursor: pointer;
            transition: 0.15s;
            height: 80px;
            box-shadow: inset -8px -8px 16px  var(--innershadowcolorb);
        }
        .genbutton3 {
            background: var(--insetcolor);
            padding:10px;
            padding-right:15px;
            padding-left:15px;
            display: block;
            margin: auto;
            width:80%;
            font-family: var(--font);
            font-weight:bold;
            font-size: 1.25em;
            color: var(--textcolor);
            border: 0px;
            border-radius: var(--borderradiusdf);
            cursor: pointer;
            transition: 0.15s;
            height: 80px;
            box-shadow: inset -8px -8px 16px  var(--innershadowcolorb);
        }
        .genbutton:hover {
            background: var(--btncolorhover);
            font-size: 1.3em;

        }
        .genbutton:active {
            background: var(--btncolorpressed);
            font-size: 1.2em;
        }
        input::file-selector-button {
            background: var(--btncolor);
            padding:10px;
            padding-right:15px;
            padding-left:15px;
            display: block;
            margin: auto;
            width:80%;
            font-family: var(--font);
            font-weight:bold;
            font-size: 1.25em;
            color: var(--textcolor);
            border: 0px;
            border-radius: var(--borderradiusdf);
            cursor: pointer;
            transition: 0.15s;
            height: 80px;
            box-shadow: inset -8px -8px 16px  var(--innershadowcolorb);
        }
        input::file-selector-button:hover {
            background: var(--btncolorhover);
            font-size: 1.3em;

        }
        input::file-selector-button:active {
            background: var(--btncolorpressed);
            font-size: 1.2em;
        }
        .genbutton2 {
            background: var(--btncolor);
            padding:30px;
            padding-right:0px;
            padding-left:0px;
            display: block;
            margin: auto;
            width:80%;
            height: 150px;
            font-family: var(--font);
            font-weight:bold;
            font-size: xx-large;
            color: var(--textcolor);
            border: 0px;
            border-radius: var(--borderradiusdf);
            cursor: pointer;
            transition: 0.15s;
            box-shadow: inset -8px -8px 16px  var(--innershadowcolorb);
        }
        .genbutton2:hover {
            background: var(--btncolorhover);
            
            font-size: 2.1em;
        }
        .genbutton2:active {
            background: var(--btncolorpressed);
            font-size: 1.9em;
        }
        .pagebutton {
            background: var(--btncolor);
            padding:0px;
            display: inline;
            width:40px;
            font-family: var(--font);
            font-weight:bold;
            font-size: 1.25em;
            color: var(--textcolor);
            border: 0px;
            border-radius: var(--borderradiusdf);
            cursor: pointer;
            transition: 0.15s;
            height: 40px;
            box-shadow: inset -8px -8px 16px  var(--innershadowcolorb);
        }
        .titleimg{
            margin: 0 auto;
            width: 80%;
            display:block;
        }
        .infocontainer{
            scrollbar-width:thin;
            scrollbar-color:var(--bgcolor),var(--scrollcolor);
            overflow-y:scroll; 
            overflow-x:hidden;
            height:1000px; 
            background: var(--insetcolor);
            padding: 15px;
            width: 80%;
            margin: auto;
            border-radius: var(--borderradiusdf);
            box-shadow: inset 8px 8px 16px  var(--innershadowcolor);
            transition: 0.15s;
        }
        .system{
            scrollbar-width:thin;
            scrollbar-color:var(--bgcolor),var(--scrollcolor);
            overflow-y:scroll; 
            overflow-x:hidden;
            height:1000px; 
            background: var(--insetcolor);
            padding: 15px;
            border-radius: var(--borderradiusdf);
            box-shadow: inset 8px 8px 16px  var(--innershadowcolor);
            transition: 0.15s;
        }
        #csvout p {
            font-family: monospace;
            font-size: medium;
        }
        a{
            color:rgb(0, 127, 255);
        }
        .systemcontainer{
            height: auto;
            background-color:rgb(0,0,0);
            border-radius: var(--borderradiusdf);
            transition: 0.15s;
        }

        .systemcontainerinterior{
            height: auto;
            background-color:rgb(0,0,0);
            border-radius: var(--borderradiusdf);
            transition: 0.15s;
        }
        ::-webkit-scrollbar {
            width: 8px;
            min-width: 8px;

        }
        ::-webkit-scrollbar-track {
            background-color:var(--bgcolor)
        }
        ::-webkit-scrollbar-thumb {
            background-color:var(--scrollcolor);
            border-radius:var(--borderradiusdf);
        }
        .red {
            color: #ff4500
        }
        .orange {
            color: #ffa800
        }
        .yellow {
            color: var(--yellow);
        }
        .darkgreen {
            color: #00a468
        }
        .lightgreen {
            color: var(--lightgreen)
        }
        .darkblue {
            color: #235083
        }
        .blue {
            color: #368fe9
        }
        .lightblue {
            color: var(--cyan)
        }
        .darkpurple {
            color: #811e9f
        }
        .purple {
            color: #b34ac0
        }
        .pink {
            color: #ff98a9
        }
        .brown {
            color: #9c6927
        }
        .black {
            color: #000000
        }
        .darkgray {
            color: #898d90
        }
        .lightgray {
            color: #d3d7da
        }
        .white {
            color: #ffffff
        }
        .typem {
            color: #ffb34f
        }
        .typek {
            color: var(--typek)
        }
        .typeg {
            color: var(--typeg);
        }
        .typef {
            color: var(--typef);
        }
        .typea {
            color: var(--typea);
        }
        .typeb {
            color: #4aa8ff
        }
        .typewd {
            color: var(--lightgreen);
        }
        .water {
            color: #727bff
        }
        .methanum {
            color: #a0a0a0
        }
        .wsubglacial {
            color: #92fbff
        }
        .ammonia {
            color: #c9cf70
        }
        .nitrogen {
            color: #7eff84
        }
        .rocky {
            color: rgb(158, 131, 103)
        }
        .icy {
            color: rgb(132, 171, 211)
        }
        .carbonaceous {
            color: rgb(219, 109, 57)
        }
        .metallic {
            color: rgb(159, 168, 168)
        }
        .icegiant {
            color: rgb(87, 156, 224)
        }
        .gasgiant {
            color: rgb(210,160,110)
        }
        .icon {
            height: 32px;
            padding: 0px;
            vertical-align: middle;
        }
        .whiteicon {

            filter: var(--whiteiconfilter);
        }
        .icon2 {
            height: 64px;
            padding: 0px;
            vertical-align: middle;
        }
        .navbar {
  height: 100%; /* Full-height: remove this if you want "auto" height */
  width: 20%; /* Set the width of the sidebar */
  position: fixed; /* Fixed Sidebar (stay in place on scroll) */
  z-index: 1; /* Stay on top */
  top: 0; /* Stay at the top */
  left: 0;
  overflow-x: hidden; /* Disable horizontal scroll */
  padding-top: 20px;
}
    .systemdisplay {
        width: 100%;
        border-radius: 16px;
        background-image: url("img/bgstars.png");
        background-size: 2048px;
        position:relative;
        display:block;
    }
    .planetdisplay {
        width: 256px;
        height: 256px;
        border-radius: 16px;
        position:relative;
        
        background-position: center;
        background-repeat: no-repeat;

    }
    .planetbg {
        background:black;
    }
    .planetoverlay {
        width: 256px;
        height: 256px;
        border-radius: 16px;
        
        top:0%;
        left:0%;
        background-position: center;
        background-repeat: no-repeat;
        position: absolute;

    }
    .planetscan {
        font-family: 'Consolas', 'Courier New', Courier, monospace;
        border-radius: var(--borderradiusdf);
            box-shadow: inset 8px 8px 16px  var(--innershadowcolor);
            background: var(--bgcolor);
            padding: 30px;
    }
    .planetscan p {
        font-family: 'Consolas', 'Courier New', Courier, monospace;
        
    }
        
    </style>
  </head>
<!--    "",
    "",
    "",
    "",
    "",
    ""-->
  <body>
    <div class="navbar">
    <img class="titleimg" src="img/titleimg.png">
    <h1> v0.3092 </h1>
    <hr>
    <h3 class="patchnotes">System Generation</h3>

    <p class="patchnotes">Number of systems to generate (>320 is very slow)</p>
    <input type="text" class="genbutton3" style="text-align:center;" placeholder="Number of systems to generate" value="1" id="numsystemsInput">
    <p></p>
    <button onClick="GenerateSector(document.getElementById('numsystemsInput').value);" class="genbutton2">Generate!</button>
    <p></p>
    <p class="patchnotes">Seed (leave blank to use random seed)</p>
    <input type="text" class="genbutton3" style="text-align:center;" placeholder="Seed (blank to use random seed)" id="seedinput">
    <p></p>
    <p class="patchnotes">Systems generated:</p>
    <p class="progress patchnotes"></p>
    <hr>
    <p></p>
    <h3 class="patchnotes">Saving and Loading</h3>
    <p></p>
    <a download="" id="download"><button onClick="download(`systems.wssg`,fullcsv(systems));" class="genbutton">Save systems as .wssg file</button></a>
    <p></p>
    <input type="button" id="loadFile" class="genbutton" value="Choose .wssg file" onclick="document.getElementById('file').click();" />
    <p></p>
    <input type="file" style="display:none;" id="file" name="file"/>
    <button onClick="loadSystem();" class="genbutton">Load selected .wssg file</button>
    <p></p>
    <hr>
    <h3 class="patchnotes">Other</h3>
    <button onClick="switchTheme();" class="genbutton">Switch theme</button>
    <p></p>
    <hr>
    <p></p>
    <div class="infocontainer" style="overflow-y:scroll; height:500px;">
        <p class="patchnotes">COMING SOON:<br> - mouseover <br> - better composition</p>
        <h3 class="patchnotes">v0.3093 - getting into the swing of things</h3>
        <P class="patchnotes">- fixed a little bit of outdated terminology</P>
        <h3 class="patchnotes">v0.3092 - tabletop version!</h3>
        <P class="patchnotes">- ported the generator to a tabletop version on request, you can find the link <a href="https://docs.google.com/document/d/1vcIC-3xI5Exhx_7GfSNIz44qizAuZ_4R-y7Uo700TO8/edit?usp=sharing">here</a> <br> - will probably make it look nicer in the future <br> - fixed some funky code</P>
        <h3 class="patchnotes">v0.3091 - a fix</h3>
        <p class="patchnotes">- added slightly more variety to the composition descriptions in the "starbound description".
        </p>
        <h3 class="patchnotes">v0.3.9 - starbounded</h3>
        <p class="patchnotes">- added a dynamically generated description inspired by starbound to the planet info <br> - this will work with existing systems
        </p>
        <h3 class="patchnotes">v0.3.8 - nccs fail</h3>
        <p class="patchnotes">- non-technological civilizations added. such 'civilizations' are like dolphins, unable to develop notable technology and only debatably civilizations at all. they are very common <br>- they're id 2 to maintain compatibility <br>- was going to add NCCS composition today but that requires rewriting a lot of how composition is handled. a mockup of roughly how it will work can be found at <a href="https://scratch.mit.edu/projects/861212610/">this Scratch project</a> <br> - removed jquery <br> - fixed the FAQ </p>
        <h3 class="patchnotes">v0.3.7 - greenhouse patch</h3>
        <p class="patchnotes">- planet atmosphere composition determination is now a bit more realistic, with the atmosphere starting as a fully generated nitrogen atmosphere, but if certain conditions are met it becomes a Venus or Mars-like atmosphere.
            <br> - the seed for a system is now displayed in the system info (however, it isn't saved)
            <br> - updated the sidebar to reduce button clutter
            <br> - changed the way a swear word is censored in the patch notes
        </p>
        <h3 class="patchnotes">v0.3.6 - the beginnings of mouseover</h3>
        <p class="patchnotes">- hovering over a planet in the system preview displays its name <br> - trust me, this is a big deal
        </p>
        <h3 class="patchnotes">v0.3.5 - wssg file overhaul</h3>
        <p class="patchnotes">- wssg file format v2.0.0 is out! <br> - this means that older .wssg files WILL break, but it should be pretty easy to adapt them to the new specs <br> - things in the wssg file are now in an order that makes much more sense <br> - squashed a bug regarding the capitalization of "TRUE" and "FALSE" in csv files</p>
        <h3 class="patchnotes">v0.3.4 - twinkle, twinkle, little star</h3>
        <p class="patchnotes">- star luminosity and proper AU measurements added <br> - ultra-cool red dwarfs added because of this <br> - the WSSG file format version is now 1.2.0 <br> - the app now uses a custom pseudorandom number generator, so specified seeds are now supported. there are 400 trillion different possible systems - that's 2000 galaxies worth of star systems! </p>
        <h3 class="patchnotes">v0.3.3_01 - the first ever minor update:</h3>
        <p class="patchnotes">- star graphics added <br> - canvases made higher res <br> - this isn't enough for a major update, resulting in my first ever minor update<br> - which also happens to be the 100th update on github so hooray</p>
        <h3 class="patchnotes">v0.3.3 - space is beautiful (and maybe a little boring):</h3>
        <p class="patchnotes">- more graphical improvements to the generator <br> - star type images added to the files, in case anyone can figure out how the f🪐ck to draw those correctly <br> - everyone's probably tired of always getting m-type stars, so I made k and g type stars more common (even if this makes the generator a little unrealistic) <br> - optimizations to system loading. mainly, I no longer use a canvas for the planet preview images, instead I stack a bunch of divs on top of each other. this makes systems generate waaaaaay faster.</p>
        <h3 class="patchnotes">v0.3.2 - clearing the neighborhood:</h3>
        <p class="patchnotes">- updated the way planets are placed in the system to more accurately represent how planets form <br> - had to remove numeric IDs because of this, but you can still find them in the csv file (all the planets will be out of order though) <br> - .wssg file format version: sv1.1.1<br>- made life types easier to understand</p>
        <h3 class="patchnotes">v0.3.1 - of jool and jostan, of kerbin and tervis:</h3>
        <p class="patchnotes">- geologic activity is now saved to .wssg files (that was kind of dumb of me to forget)<br>- added a bunch more varieties for planet appearances to make things look a bit more interesting<br>- default solar system file updated, and the app now loads that file when starting up<br>- old imported .wssg files keep the basic planet sprites<br>- current .wssg file format version: sv1.1.0</p>
        <h3 class="patchnotes">v0.3.0 - saving and loading:</h3>
        <p class="patchnotes">- CSV IMPORT IS HERE! System customization is now fully supported (though I might make the process a bit more user friendly in the future.) <br>- files are now .wssg, they're just csv files though, this change is more meant to represent csv as a save format instead of just an export format.<br>- current .wssg file format version: sv1.0.0<br>- squashed a bug with distant companion planet generation</p>
        <h3 class="patchnotes">v0.2.11 - color me impressed:</h3>
        <p class="patchnotes">- added a function, refreshSystem(id), that you can use to refresh the system display if you've made edits using the debug console. <br>- added more themes, including the green theme from before 0.2.7, and one inspired by 2048, my first experience with a github web-app<br>- next update will probably be progress on csv import</p>
        <h3 class="patchnotes">v0.2.10 - the missing update:</h3>
        <p class="patchnotes">- hot jupiters don't appear around red dwarfs<br>- improved the look of the page buttons</p>
        <h3 class="patchnotes">v0.2.9 - dayside:</h3>
        <p class="patchnotes">- added light mode (in case you wanted to use light mode)<br>- systems are now displayed in pages<br>- systems now generate much faster<br>- brought back 500 systems button and upgraded it to a 1000 systems button to celebrate</p>
        <h3 class="patchnotes">v0.2.8 - what's in a name:</h3>
        <p class="patchnotes">- fixed csv export<br> - gave everything randomly generated names</p>
        <h3 class="patchnotes">v0.2.7 - hot jupiters:</h3>
        <p class="patchnotes">- Added Hot Jupiters<br> - Made moons not generate close to the star <br> - Added Traveller's universal """world""" profile (hint: it tells you next to nothing about the world)<br> - More UI upgrades<br> - Made icy planets way more common</p>
        <h3 class="patchnotes">v0.2.6 - a bug:</h3>
        <p class="patchnotes">- GAS GIANT MOONS ARE FINALLY THE RIGHT SIZE, THIS BUG HAS BEEN IN THE APP SINCE 0.0.1<br> - added a sidebar so that you don't have to scroll down a bunch to find everything <br> - probably just ruined things for mobile users<br> - ah well<br> </p>
        <h3 class="patchnotes">v0.2.5 - rings and other things:</h3>
        <p class="patchnotes">- uberplanet changed to euplanet at Azi's suggestion <br> - added rings to planets<br> - added a new seecret feature<br> </p>
        <h3 class="patchnotes">v0.2.4 - omg the planets:</h3>
        <p class="patchnotes">- improved planet rendering! <br> - performance fixes and progress indicator for bulk generating systems</p>
        <h3 class="patchnotes">v0.2.3 - icons:</h3>
        <p class="patchnotes">- graphical updates: <br> - changed the font to the one I use for google docs<br> - added icons for EVERYTHING <br> </p>
        <h3 class="patchnotes">v0.2.2 - colorful update:</h3>
        <p class="patchnotes">- planet info is now color coded<br> - lmn if this looks ugly</p>
        <h3 class="patchnotes">v0.2.1 - units:</h3>
        <p class="patchnotes">- radius and density are now displayed in traditional units, and temperature is displayed in C as well as K<br> - planets now specify their type (uberplanet, dwarf planet, satellite planet)</p>
        <h3 class="patchnotes">hotfix:</h3>
        <p class="patchnotes">- removed excess &lt;br> tags from csv file</p>
        <h3 class="patchnotes">v0.2.0 - csv update:</h3>
        <p class="patchnotes">- CSV DOWNLOAD FUNCTIONALITY ADDED <br> - tweaked planet sizes so now small and Earth-sized planets are a bit more common <br> - new logo that should hopefully fit the aesthetic more</p>
        <h3 class="patchnotes">v0.1.6 - more csv progress:</h3>
        <p class="patchnotes">- fixed the absolute mess of a patchnote from the previous version<br> - some small terminology improvements<br> - life now shows what liquid it uses<br> - more internal csv work. you can now get a csv dump of the systems by typing "fullcsv(systems)" in the debug console, but I have yet to put it in a ui usable format. 0.2 coming soon!</p>
        <h3 class="patchnotes">v0.1.5 - au-sun:</h3>
        <p class="patchnotes">- made some generation of planet types, gas giants, moons somewhat more realistic<br> - internal changes to prepare for csv export functionality (that I won't bore you with explaining)<br> - updated distance display to now give you the equivalent distance from the sun</p>
        <h3 class="patchnotes">v0.1.4 - speak english please:</h3>
        <p class="patchnotes">- updated the language used for star types and temperatures <br> - added approximate temperature measurements in kelvin to help with reading of the temperature labels <br> - made planets more common closer to the star, and made it so larger planets tend to have thicker atmospheres <br> - added another generate button for 500 systems</p>
        <h3 class="patchnotes">v0.1.3 - cloudy cove:</h3>
        <p class="patchnotes">- added atmosphere and surface liquid visualization to the diagrams</p>
        <h3 class="patchnotes">v0.1.2 - scrolllllll:</h3>
    <p class="patchnotes">- added scrollbars to things</p>
    <h3 class="patchnotes">v0.1.1 - just right:</h3>
    <p class="patchnotes">- added color to system diagrams to indicate star types, composition of planets, aquatic goldilocks zone (since people seem to care about that) <br> - some star systems now just have many fewer planets <br> - finally the white dwarf temperature check works</p>
    <h3 class="patchnotes">v0.1.0 - diagrams:</h3>
    <p class="patchnotes">- system diagrams added</p>
    <h3 class="patchnotes">v0.0.4 - sector four:</h3>
    <p class="patchnotes">- formatting improvements <br> - 'generate sector' button generates 125 systems <br> - attempted to fix white dwarf planets</p>
    <h3 class="patchnotes">v0.0.3 - look at this logo:</h3>
    <p class="patchnotes">- style overhaul, added logo <br> - tried to add check for planets around white dwarfs to always be the coldest possible temperature</p>
    <h3 class="patchnotes">v0.0.2 - the update after the beginning:</h3>
    <p class="patchnotes">- planet statistics now show in a more readable format</p>
    <h3 class="patchnotes">v0.0.1 - the beginning:</h3>
    <p class="patchnotes">- generator is... functional</p>
    </div>
    <p></p>
    <div class="infocontainer" style="overflow-y:scroll; height:500px;">
        <h1 class="patchnotes">FAQ</h1>
        <p class="patchnotes"><strong>Q: What's an AU☉?</strong><br> A: A measurement I made to help describe the layout of systems. One AU☉ is the distance Earth would need to be from the system's main star(s) to have the same surface temperature.</p>
        <p class="patchnotes"><strong>Q: What's a seed?</strong><br> A: A seed is the base number the app uses to generate a system. The same seed always gives the same generated system. For example, the seed 466896111676924 (at least on 0.3.4) gives a star system with a rare blue giant star. Note that asteroid belt backgrounds and starfields are purely cosmetic, so they are generated using Javascript's internal random generator, which doesn't follow the seed.</p>
        <p class="patchnotes"><strong>Q: Why are my white dwarfs so bright?</strong><br> A: A white dwarf's 'luminosity' is how bright it was as a main sequence star. This is done so that planets can be placed correctly around white dwarfs. You may notice that all the planets are very cold to account for the white dwarf in reality being very dim.</p>
        <p class="patchnotes"><strong>Q: Why is 340K (67*C) "lukewarm"? Why is 170K (-103*C) "cool"? (Etc.) </strong><br> A: 340 Kelvin may be very hot for humans, and 170K very cold, but keep in mind we're dealing with planets as hot as 1200K and as cold as 50K! This means that temperatures are described in a more moderate manner than usual.</p>
        <p class="patchnotes"><strong>Q: Why is life so common? </strong><br> A: Icy worlds with subsurface oceans are promising candidates for life. This is partially because they are very stable, and unlikely to be affected by astronomical events that would spell disaster on planets like Earth.</p>
        <p class="patchnotes"><strong>Q: Major planet? What's that? </strong><br> A: A major planet refers to the traditional definition of a planet as needing to clear its neighborhood.</p>
        <p class="patchnotes"><strong>Q: Why are there so few planets in my system? </strong><br> A: Is there a gas giant close to the star? If so, it's because the gas giant migrated inward and destroyed or ejected any planets in its path.</p>
        <p class="patchnotes"><strong>Q: What is the NCCS? </strong><br> A: The No-Classification Classification System. Ideally, the planet description system used for WSSG, however it hasn't quite been implemented (as seen by the atmospheres and compositions).</p>
        <p class="patchnotes"><strong>Q: Dwarf planets aren't planets! / Moons aren't planets!</strong><br> A: I disagree. I have <a href="https://www.youtube.com/watch?v=W7qZ52QHXrs">a video</a> on this topic if you want to know the details.</p>
        <p class="patchnotes"><strong>Q: How is there life with no water? </strong><br> A: It's probably either subglacial - meaning it's in the subsurface ocean under the crust of an icy planet - or it's methanic or ammonic.</p>
        <p class="patchnotes"><strong>Q: Why is there no oxygen in the atmosphere? </strong><br> A: Oxygen requires photosynthetic producers like plants, so I've simulated the presence of oxygen based on multicellular life.</p>
        <p class="patchnotes"><strong>Q: Why are Earth-like planets so rare? </strong><br> A: Minsharic (Earth-like) planets are rare because the set of 'Earth-like' conditions are very precise. However, habitability doesn't require a planet to be precisely like Earth.</p>
        <p class="patchnotes"><strong>Q: How do I see the habitable zone? </strong><br> A: The concept of a 'habitable zone' is rather fuzzy, given the wildly varying surface conditions that could make surface water possible or not. The green region of a system diagram denotes the region where water could exist given Earth-like atmospheric conditions, about 0.6-1.1 AU☉.</p>
        <p class="patchnotes"><strong>Q: Well ackshually, from 0.95 AU☉ and closer the planet has a runaway greenhouse effect- </strong><br> A: I've seen these claims and I acknowledge them. However, there is an oddity with it - it relates to oceans boiling causing something something chemistry a bunch of carbon dioxide is released. The problem is, even with an Earth-like atmosphere, you need to be way closer to a star than 0.95 AU☉ for oceans to start boiling. I just simulate this directly.</p>
        <p class="patchnotes"><strong>Q: Why are my dwarf planet moons ordered weirdly? </strong><br> A: Dwarf planet moons are positioned after the entire asteroid belt due to a technical limitation. This may or may not be fixed in the future. I personally don't see it as too big of an issue.</p>
        <p class="patchnotes"><strong>Q: What the heck is methanum? </strong><br> A: Liquid methane. It's a term Astro Pro uses for liquid methane, and that I like.</p>
        <p class="patchnotes"><strong>Q: How do I export to CSV? </strong><br> A: Hit 'Save systems as .wssg file' and save the file. A .wssg file is a csv file containing the system(s)' information</p>
        <p class="patchnotes"><strong>Q: What is a .wssg file? </strong><br> A: A .wssg file is just a csv file. It's a special file extension because these files can also be loaded by the software to display saved systems.</p>
        <p class="patchnotes"><strong>Q: How do I make custom systems? </strong><br> A: A custom system is a .wssg (csv) file containing the system(s)' information. Each planet is a row with all of the planet's data, there is a guide as to how to read the data at <a href=https://github.com/Vector-Graphics/walkersysgen/blob/main/README.md>the readme</a>. Just modify the file using your favorite spreadsheet editor, save it as csv, and you can load your custom system!</p>
        <p class="patchnotes"><strong>Q: What do all the numbers in the exported file mean? </strong><br> A: The numbers under 'composition', 'temperature', etc are usually internal IDs for the respective classes (hot, cold, etc). There is a table of what the numbers mean at <a href=https://github.com/Vector-Graphics/walkersysgen/blob/main/README.md>the readme</a>.</p>
        <p class="patchnotes"><strong>Q: What does bepis mean? / Why is my planet's [whatever] 'bepis'?</strong><br> A: I use 'bepis' for unintended values in certain arrays. 'bepis' appearing in CSVs for names of stars that don't exist is intentional, and additionally, 'Bepis' capitalized is just a very rare possibility for a randomly generated name (be + pi + s). If this isn't that, you can report it as a bug on <a href=https://github.com/Vector-Graphics/walkersysgen/issues>the issues page</a>.</p>
        <p class="patchnotes"><strong>Q: Why are all the planets out of order in the exported file?</strong><br> A: Planets aren't listed in order of distance from the sun, they are instead listed in "order of formation", meaning the order they were placed in the system. In general, more massive planets have lower IDs.</p>
        <p class="patchnotes"><strong>Q: How do I suggest a feature? </strong><br> A: Using <a href=https://github.com/Vector-Graphics/walkersysgen/issues>the issues page</a>.</p>
        <p class="patchnotes"><strong>Q: Demi-civilization? </strong><br> A: A social species that meets some of the criteria for having civilization, but not all of them.</p>
    </div>
    <p></p>

    </div>
    <div class="main">
        <div class="patchnotes"></p>
        <button onClick="decrementPages();" class="genbutton pagebutton">←</button>
        <span id="pagenumber"></span>
        <button onClick="incrementPages();" class="genbutton pagebutton">→</button>
        </div>
        <p></p>
        <div class="systemcontainer"></div>
    </div>

    <p></p>
    <script> 
class Planet{
    constructor(size,composition,density,atmobasegas,atmothickness,greenhouse,liquid,lcoverage,sizeindex,sizeclass,geoactive,life,orbit,basetemp,temperature,parentbody,id,type,moons,starsystem,oxygentag,beltlength,moonnumber=-1,displayseed=0,rings=0,civ=0,name="bepis") {
        this.size=size;
        this.composition=composition;
        this.density=density;
        this.atmobasegas=atmobasegas;
        this.atmothickness=atmothickness;
        this.greenhouse=greenhouse;
        this.liquid=liquid;
        this.lcoverage=lcoverage;
        this.sizeindex=sizeindex;
        this.sizeclass=sizeclass;
        this.geoactive=geoactive;
        this.life=life;
        this.orbit=orbit;
        this.basetemp=basetemp;
        this.temperature=temperature;
        this.parentbody=parentbody;
        this.id=id;
        this.type=type;
        this.moons=moons;
        this.starsystem=starsystem;
        this.oxygentag=oxygentag;
        this.beltlength=beltlength;
        this.moonnumber=moonnumber; 
        this.displayseed=displayseed;
        this.rings=rings;
        this.civ=civ;
        this.name=name;
    }
}
class System{
    constructor(planets,primarystartype,closecompanionpresent,closecompanionstartype,distantcompanionpresent,distantcompanionstartype,primaryage,secondaryage,primaryname="bepis",closecompanionname="bepis",distantcompanionname="bepis",primaryluminosity=1,closecompanionluminosity=1,distantcompanionluminosity=1,seed="(User-created)"){
        this.planets=planets;
        this.primarystartype=primarystartype;
        this.closecompanionpresent=closecompanionpresent;
        this.closecompanionstartype=closecompanionstartype;
        this.distantcompanionpresent=distantcompanionpresent;
        this.distantcompanionstartype=distantcompanionstartype;
        this.primaryage=primaryage;
        this.secondaryage=secondaryage;
        this.primaryname=primaryname;
        this.closecompanionname=closecompanionname;
        this.distantcompanionname=distantcompanionname;
        this.primaryluminosity=primaryluminosity;
        this.closecompanionluminosity=closecompanionluminosity;
        this.distantcompanionluminosity=distantcompanionluminosity;
        this.seed=seed;
    }
}

var systems;

var startypetable = [
    6,
    5,
    4,
    4,
    4,
    3,
    3,
    3,
    3,
    3,
    3,
    2,
    2,
    2,
    2,
    2,
    2,
    2,
    2,
    2,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1
]

var hexadecimalDigits = [
    '0',
    '1',
    '2',
    '3',
    '4',
    '5',
    '6',
    '7',
    '8',
    '9',
    'A',
    'B',
    'C',
    'D',
    'E',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',
    'F',

]

var imgsrcs =[
    "img/ATM_carbo.png",
    "img/staricons/typea.png",
    "img/staricons/typeb.png",
    "img/staricons/typef.png",
    "img/staricons/typeg.png",
    "img/staricons/typek.png",
    "img/staricons/typem.png",
    "img/ATM_nitro.png",
    "img/bgstars.png",
    "img/planeticons/ammoniaOverlay1.png",
    "img/planeticons/ammoniaOverlay2.png",
    "img/planeticons/ammoniaOverlay3.png",
    "img/planeticons/carbonaceousPlanet.png",
    "img/planeticons/carbonaceousPlanet2.png",
    "img/planeticons/carbonaceousPlanet3.png",
    "img/planeticons/carbonaceousPlanet4.png",
    "img/planeticons/carbonaceousPlanet5.png",
    "img/planeticons/carbonaceousPlanet6.png",
    "img/planeticons/gasGiant.png",
    "img/planeticons/gasGiant2.png",
    "img/planeticons/gasGiant3.png",
    "img/planeticons/gasGiant4.png",
    "img/planeticons/gasGiant5.png",
    "img/planeticons/gasGiant6.png",
    "img/planeticons/geoActiveOverlay2.png",
    "img/planeticons/geoInactiveOverlay.png",
    "img/planeticons/iceGiant.png",
    "img/planeticons/iceGiant2.png",
    "img/planeticons/iceGiant3.png",
    "img/planeticons/iceGiant4.png",
    "img/planeticons/iceGiant5.png",
    "img/planeticons/iceGiant6.png",
    "img/planeticons/icyPlanet.png",
    "img/planeticons/icyPlanet2.png",
    "img/planeticons/icyPlanet3.png",
    "img/planeticons/icyPlanet4.png",
    "img/planeticons/icyPlanet5.png",
    "img/planeticons/icyPlanet6.png",
    "img/planeticons/lifeIndicator.png",
    "img/planeticons/lifeOverlayAmmonia.png",
    "img/planeticons/lifeOverlayMethanum.png",
    "img/planeticons/lifeOverlayWater.png",
    "img/planeticons/metallicPlanet.png",
    "img/planeticons/metallicPlanet2.png",
    "img/planeticons/metallicPlanet3.png",
    "img/planeticons/metallicPlanet4.png",
    "img/planeticons/metallicPlanet5.png",
    "img/planeticons/metallicPlanet6.png",
    "img/planeticons/methaneOverlay1.png",
    "img/planeticons/methaneOverlay2.png",
    "img/planeticons/methaneOverlay3.png",
    "img/planeticons/nitrogenOverlay1.png",
    "img/planeticons/nitrogenOverlay2.png",
    "img/planeticons/nitrogenOverlay3.png",
    "img/planeticons/rockyPlanet.png",
    "img/planeticons/rockyPlanet2.png",
    "img/planeticons/rockyPlanet3.png",
    "img/planeticons/rockyPlanet4.png",
    "img/planeticons/rockyPlanet5.png",
    "img/planeticons/rockyPlanet6.png",
    "img/planeticons/shade.png",
    "img/planeticons/shade2.png",
    "img/planeticons/torridPlanetOverlay.png",
    "img/planeticons/waterOverlay1.png",
    "img/planeticons/waterOverlay2.png",
    "img/planeticons/waterOverlay3.png",
]

var orbittable = [
    "<span class='red'>0.1</span>",
    "<span class='red'>0.2</span>",
    "<span class='red'>0.3</span>",
    "<span class='orange'>0.4</span>",
    "<span class='orange'>0.5</span>",
    "<span class='darkgreen'>0.6</span>",
    "<span class='darkgreen'>0.7</span>",
    "<span class='darkgreen'>0.8</span>",
    "<span class='darkgreen'>0.9</span>",
    "<span class='darkgreen'>1</span>",
    "<span class='darkgreen'>1.2</span>",
    "<span class='lightblue'>1.4</span>",
    "<span class='lightblue'>1.6</span>",
    "<span class='lightblue'>1.8</span>",
    "<span class='lightblue'>2</span>",
    "<span class='lightblue'>2.3</span>",
    "<span class='lightblue'>2.6</span>",
    "<span class='lightblue'>2.9</span>",
    "<span class='blue'>3.2</span>",
    "<span class='blue'>3.5</span>",
    "<span class='blue'>4</span>",
    "<span class='blue'>4.5</span>",
    "<span class='blue'>5</span>",
    "<span class='blue'>5.5</span>",
    "<span class='blue'>6</span>",
    "<span class='blue'>7</span>",
    "<span class='blue'>8</span>",
    "<span class='blue'>9</span>",
    "<span class='blue'>10</span>",
    "<span class='blue'>12</span>",
    "<span class='blue'>14</span>",
    "<span class='blue'>16</span>",
    "<span class='blue'>18</span>",
    "<span class='blue'>20</span>",
    "<span class='blue'>23</span>",
    "<span class='blue'>26</span>",
    "<span class='blue'>29</span>",
    "<span class='blue'>34</span>",
    "<span class='blue'>38</span>",
    "<span class='blue'>42</span>",
    "<span class='blue'>46</span>",
    "<span class='blue'>50</span>"
]

var consonants = [
    "m", "t", "c", "b", "k", "l", "r", "n", "v", "th", "f", "j", "p", "d", "g", "st", "m", "t", "c", "b", "k", "l", "n", "v", "th", "f", "j", "p", "d", "g", "st", "rh", "br", "tr", "", "pl", "s", "sh", "sc", "h", "ch", "ph", "gl", "fl", "cl", "bl", "sch", "", "", "", "", ""
]
var vowels = [
    "a", "e", "i", "o", "u",
]
var glides = [
    "r", "", ""
]
function syllable(){
    if(prng() >= 0.5){
        return consonants[dice(1,consonants.length)]+vowels[dice(1,vowels.length)]+glides[dice(1,glides.length)];
    }else{
        return namepenul[dice(1,namepenul.length)];
    }
    
    
}
var nameparts = [
    "mer", "tar", "mar", "cur", "mur", "cer", "ter", "bur", "ber", "bir", "cir", "ker", "cu", "la", "lar", "bar", "ba", "me", "ry", "re", "ro", "ra", "nu", "ve", "va", "var", "ra", "ce", "re", "sa", "tha", "fa", "tur", "ju", "pi", "da", "i", "o", "pa", "par", "ga", "ny", "cal", "li", "sto", "la", "ti", "ta", "te", "thy", "di", "rhe", "a", "pe", "tu", "ri", "bri", "ni", "be", "ro", "tri", "to", "u", "ra", "e", "ne", "p", "tu", "ne", "plu", "ri", "ma", "ke", "qua", "ar", "se", "na", "tasci", "ti", "sci", "fer", "n", "lar", "sta", "ste", "re", "plo", "cha", "ro", "bi", "mo", "ho", "du", "na", "mi", "mu", "ty", "lo", "bor",  
]
var namepenul = [
"mer", "tar", "mar", "cur", "mur", "cer", "ter", "bur", "ber", "bir", "cir", "ker", "cu", "la", "lar", "bar", "ba", "me", "ry", "re", "ro", "ra", "nu", "ve", "va", "var", "ra", "ce", "re", "sa", "tha", "fa", "tur", "ju", "pi", "da", "i", "o", "pa", "par", "ga", "ny", "cal", "li", "sto", "la", "ti", "ta", "te", "thy", "di", "rhe", "a", "pe", "tu", "ri", "bri", "ni", "be", "ro", "tri", "to", "u", "ra", "e", "ne", "tu", "ne", "plu", "ri", "ma", "ke", "qua", "ar", "se", "na", "tasci", "ti", "sci", "fer", "lar", "sta", "ste", "re", "plo", "cha", "ro", "bi", "mo", "ho", "du", "na", "mi", "mu", "ty", "lo", "bor", 
]
var nameends = [
    "s", "", "", "n", "t"
]
var orbittable2 = [
    "0.1",
    "0.2",
    "0.3",
    "0.4",
    "0.5",
    "0.6",
    "0.7",
    "0.8",
    "0.9",
    "1",
    "1.2",
    "1.4",
    "1.6",
    "1.8",
    "2",
    "2.3",
    "2.6",
    "2.9",
    "3.2",
    "3.5",
    "4",
    "4.5",
    "5",
    "5.5",
    "6",
    "7",
    "8",
    "9",
    "10",
    "12",
    "14",
    "16",
    "18",
    "20",
    "23",
    "26",
    "29",
    "34",
    "38",
    "42",
    "46",
    "50",
]
var imageobjs = {

}
var uberplanetsizes = [0.04, 0.06, 0.1, 0.15, 0.2, 0.3, 0.4, 0.55, 0.7, 0.85, 1, 1.1, 1.25, 1.5, 1.8, 2.3, 2.9, 3.5, 4.3, 6, 8, 10, 13, 16, 20, 25, 30, 35, 45, 60, 80, 100, 200, 300, 500, 800]
var letters = ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX","XXI","XXII","XXIII","XXIV","XXV","XXVI"]
var unterplanetsizes = [0.00007,
0.00008,
0.00009,
0.0001,
0.00011,
0.00012,
0.00014,
0.00016,
0.00018,
0.00021,
0.00024,
0.00027,
0.0003,
0.00033,
0.00037,
0.0004,
0.00043,
0.00047,
0.0005,
0.00053,
0.00057,
0.0006,
0.00063,
0.00067,
0.0007,
0.0008,
0.0009,
0.001,
0.0011,
0.0012,
0.0014,
0.0017,
0.0020,
0.0024,
0.0029,
0.0035
]

var untermoonsizes = [0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
]

var smubermoonsizes = [0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.0003,
0.00033,
0.0004,
0.001,
0.003,
0.01,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.0003,
0.00033,
0.0004,
0.001,
0.003,
0.01,
0.00007,
0.00009,
0.00012,
0.00016,
0.00021,
0.00027,
0.0003,
0.00033,
0.0004,
0.001,
0.003,
0.01
]

var meubermoonsizes = [
0.00007,
0.00012,
0.00016,
0.0003,
0.0007,
0.0015,
0.0028,
0.004,
0.007,
0.01,
0.02,
0.04,
0.00007,
0.00012,
0.00016,
0.0003,
0.0007,
0.0015,
0.0028,
0.004,
0.007,
0.01,
0.02,
0.04,
0.00007,
0.00012,
0.00016,
0.0003,
0.0007,
0.0015,
0.0028,
0.004,
0.007,
0.01,
0.02,
0.04,
]

var age;

var laubermoonsizes = [
0.00007,
0.00012,
0.00016,
0.0003,
0.0007,
0.0012,
0.003,
0.005,
0.008,
0.01,
0.015,
0.02,
0.025,
0.03,
0.04,
0.06,
0.08,
0.1,
0.00007,
0.00012,
0.00016,
0.0003,
0.0007,
0.0012,
0.003,
0.005,
0.008,
0.01,
0.015,
0.02,
0.025,
0.03,
0.04,
0.06,
0.08,
0.1,
]
var laubermoonsizes2 = [
0.00007,
0.00014,
0.00028,
0.00056,
0.00112,
0.002,
0.005,
0.011,
0.03,
0.07,
0.16,
0.3,
0.6,
0.9,
1.1,
1.3,
1.5,
1.7,
0.00007,
0.00014,
0.00028,
0.00056,
0.00112,
0.002,
0.005,
0.011,
0.03,
0.07,
0.16,
0.3,
0.6,
0.9,
1.1,
1.3,
1.5,
1.7,
]
var basetemptable = [
    16,
    15,
    14,
    13,
    12,
    11,
    10,
    9, // temperate
    9,
    8,
    8,
    7,
    6,
    6,
    5,
    5,
    4,
    4,
    4,
    3,
    3,
    3,
    3,
    3,
    2,
    2,
    2,
    1,
    1,
    1,
    1,
    1,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
    0,
]

var greenhousetable = [
    [0,  0,  0,  0,  1,  4],
    [1,  1,  1,  2,  2,  5],
    [2,  2,  2,  3,  3,  7],
    [3,  3,  3,  4,  4,  8],
    [4,  4,  4,  5,  6,  9],
    [5,  5,  6,  6,  7,  10],
    [6,  6,  6,  7,  8,  11],
    [7,  7,  8,  9,  10, 13],
    [8,  9,  9,  10, 11, 14],
    [9,  10, 10, 11, 13, 15],
    [10, 11, 12, 13, 14, 16],
    [11, 12, 12, 13, 14, 16],
    [12, 13, 13, 14, 15, 17],
    [13, 14, 14, 15, 15, 17],
    [14, 14, 15, 15, 16, 17],
    [15, 15, 15, 16, 17, 18],
    [16, 16, 16, 17, 17, 18],

]

var liquidcoveragetable = [
    0.02,
    0.05,
    0.1,
    0.3,
    0.7,
    0.8,
    0.9,
    0.97,
    1,
    -1,
    -1,
    -1
]

var validorbits = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var validorbitsreset = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];

var compositionnames = [
    "<img class='icon' src='img/iconRocky.png'><span class='rocky'>rocky</span>",
    "<img class='icon' src='img/iconIcy.png'><span class='icy'>icy</span>",
    "<img class='icon' src='img/iconCarbonaceous.png'><span class='carbonaceous'>carbonaceous</span>",
    "<img class='icon' src='img/iconMetallic.png'><span class='metallic'>metallic</span>",
    "n <img class='icon' src='img/iconIceGiant.png'><span class='icegiant'>ice giant</span>",
    " <img class='icon' src='img/iconGasGiant.png'><span class='gasgiant'>gas giant</span>"
]

var lifenames_atmo = [
    "",    
    ", <img class='icon' src='img/iconOxygen.png'><span class='red'>oxygen</span>"
]

var parentbodynames = {
    false: "⠀⠀",
    true: "⠀⠀⠀⠀"
}

var parentbodynames2 = {
    false: "",
    true: "⠀⠀"
}

var vapornames = [
    "",
    ", <img class='icon' src='img/iconWater.png'><span class='water'>water vapor</span>",
    ", <img class='icon' src='img/iconAmmonia.png'><span class='ammonia'>ammonia</span>",
    ", <img class='icon' src='img/iconMethane.png'><span class='methanum'>methane</span>",
    ""
]

var compcolors = [
    ["img/planeticons/rockyPlanet.png","img/planeticons/rockyPlanet2.png","img/planeticons/rockyPlanet3.png","img/planeticons/rockyPlanet4.png","img/planeticons/rockyPlanet5.png","img/planeticons/rockyPlanet6.png",],
    ["img/planeticons/icyPlanet.png","img/planeticons/icyPlanet2.png","img/planeticons/icyPlanet3.png","img/planeticons/icyPlanet4.png","img/planeticons/icyPlanet5.png","img/planeticons/icyPlanet6.png",],
    ["img/planeticons/carbonaceousPlanet.png","img/planeticons/carbonaceousPlanet2.png","img/planeticons/carbonaceousPlanet3.png","img/planeticons/carbonaceousPlanet4.png","img/planeticons/carbonaceousPlanet5.png","img/planeticons/carbonaceousPlanet6.png",],
    ["img/planeticons/metallicPlanet.png","img/planeticons/metallicPlanet2.png","img/planeticons/metallicPlanet3.png","img/planeticons/metallicPlanet4.png","img/planeticons/metallicPlanet5.png","img/planeticons/metallicPlanet6.png",],
    ["img/planeticons/iceGiant.png","img/planeticons/iceGiant2.png","img/planeticons/iceGiant3.png","img/planeticons/iceGiant4.png","img/planeticons/iceGiant5.png","img/planeticons/iceGiant6.png",],
    ["img/planeticons/gasGiant.png","img/planeticons/gasGiant2.png","img/planeticons/gasGiant3.png","img/planeticons/gasGiant4.png","img/planeticons/gasGiant5.png","img/planeticons/gasGiant6.png",]
]

var greenhousenames = [
    ", negligible",
    ", <span class='yellow'>mild</span>",
    ", <span class='yellow'>moderate</span>",
    ", <span class='orange'>strong</span>",
    ", <span class='orange'>severe</span>",
    ", <span class='red'>runaway</span>",
]

var liquidnames = [
    "",
    "<img class='icon' src='img/iconWater.png'><span class='water'>water</span>",
    "<img class='icon' src='img/iconAmmonia.png'><span class='ammonia'>ammonia</span>",
    "<img class='icon' src='img/iconMethane.png'><span class='methanum'>methanum</span>",
    "<img class='icon' src='img/iconNitrogenLiquid.png'><span class='nitrogen'>nitrogen</span>"
]

var liquidnames2 = [
    "",
    "water",
    "ammonia",
    "methane",
    "nitrogen",
]

var liquidnameslife = [
    "water-based (subglacial)",
    "water-based (surface)",
    "ammonia-based (surface)",
    "methane-based (surface)",
    "water-based (subglacial)"
]

var spancolorslife = [
    "<span class='purple'>",
        "<span class='purple'>",
            "<span class='purple'>",
                "<span class='purple'>",
                    "<span class='purple'>"
]

var atmothicknessnames = [
    "none",
    "<img class='icon' src='img/iconAtmo1.png'><span class='typeb'>very thin</span>",
    "<img class='icon' src='img/iconAtmo2.png'><span class='typeb'>thin</span>",
    "<img class='icon' src='img/iconAtmo3.png'><span class='typea'>somewhat thin</span>",
    "<img class='icon' src='img/iconAtmo4.png'><span class='typea'>medium</span>",
    "<img class='icon' src='img/iconAtmo5.png'><span class='typef'>thick</span>",
    "<img class='icon' src='img/iconAtmo6.png'><span class='typef'>very thick</span>"
]
var atmothicknessnames2 = [
    "none",
    "very thin",
    "thin",
    "somewhat thin",
    "medium",
    "thick",
    "very thick"
                    ]
var typenames = [
    "<img class='icon whiteicon' src='img/iconUberplanet.png'> MAJOR PLANET",
    "<img class='icon whiteicon' src='img/iconUnterplanet.png'> DWARF PLANET",
    "<img class='icon whiteicon' src='img/iconSatellite.png'> SATELLITE PLANET",
    "<img class='icon whiteicon' src='img/iconSatellite.png'> SATELLITE PLANET",
    "<img class='icon whiteicon' src='img/iconSatellite.png'> SATELLITE PLANET",
    "<img class='icon whiteicon' src='img/iconSatellite.png'> SATELLITE PLANET",
    "<img class='icon whiteicon' src='img/iconSatellite.png'> SATELLITE PLANET"
]
var temperaturenames = [
    "<img class='icon' src='img/iconTemp1.png'><span class='purple'>frigid</span> (~50K, ~-220C)",
    "<img class='icon' src='img/iconTemp1.png'><span class='purple'>frozen</span> (~70K, ~-200C)",
    "<img class='icon' src='img/iconTemp2.png'><span class='blue'>gelid</span> (~100K, ~-170C)",
    "<img class='icon' src='img/iconTemp2.png'><span class='blue'>cold</span> (~120K, ~-150C)",
    "<img class='icon' src='img/iconTemp2.png'><span class='blue'>chilly</span> (~150K, ~-120C)",
    "<img class='icon' src='img/iconTemp3.png'><span class='lightblue'>cool</span> (~170K, ~-100C)",
    "<img class='icon' src='img/iconTemp3.png'><span class='lightblue'>aretian</span> (~190K, ~-80C)",
    "<img class='icon' src='img/iconTemp3.png'><span class='lightblue'>huronian</span> (~220K, ~-50C)",
    "<img class='icon' src='img/iconTemp4.png'><span class='lightgreen'>sturtian</span> (~250K, ~-20C)",
    "<img class='icon' src='img/iconTemp4.png'><span class='lightgreen'>temperate</span> (~280K, ~10C)",
    "<img class='icon' src='img/iconTemp4.png'><span class='lightgreen'>tepid</span> (~310K, ~40C)",
    "<img class='icon' src='img/iconTemp5.png'><span class='yellow'>lukewarm</span> (~340K, ~70C)",
    "<img class='icon' src='img/iconTemp5.png'><span class='yellow'>warm</span> (~375K, ~105C)",
    "<img class='icon' src='img/iconTemp5.png'><span class='yellow'>toasty</span> (~425K, ~155C)",
    "<img class='icon' src='img/iconTemp6.png'><span class='orange'>hot</span> (~500K, ~230C)",
    "<img class='icon' src='img/iconTemp6.png'><span class='orange'>sweltering</span> (~600K, ~330C)",
    "<img class='icon' src='img/iconTemp6.png'><span class='orange'>veneran</span> (~750K, ~480C)",
    "<img class='icon' src='img/iconTemp7.png'><span class='red'>scorched</span> (~900K, ~630C)",
    "<img class='icon' src='img/iconTemp7.png'><span class='red'>torrid</span> (~1200K, ~930C)"
]

var temperaturenames2 = [
    "a frigid -220C",
    "a freezing -200C",
    "a gelid -170C",
    "a cold -150C",
    "a chilly -120C",
    "a cool -100C",
    "an aretian -80C",
    "a huronian -50C",
    "a sturtian -20C",
    "a temperate 10C",
    "a tepid 40C",
    "a lukewarm 70C",
    "a warm 105C",
    "a toasty 155C",
    "a hot 230C",
    "a sweltering 330C",
    "a veneran 480C",
    "a scorching 630C",
    "a torrid 930C"
]


var lifenames = [
    "no",
    "<img class='icon' src='img/iconProkaryotic.png'>unicellular",
    "<img class='icon' src='img/iconMulticellular.png'>multicellular"
]

var startypes = [
    "<img class='icon2' src='img/iconClassWD.png'><span class='typewd'>white dwarf</span>",
    "<img class='icon2' src='img/iconClassM.png'><span class='typem'>M-type main sequence star",
    "<img class='icon2' src='img/iconClassK.png'><span class='typek'>K-type main sequence star",
    "<img class='icon2 whiteicon' src='img/iconClassG.png'><span class='typeg'>G-type main sequence star",
    "<img class='icon2' src='img/iconClassF.png'><span class='typef'>F-type main sequence star",
    "<img class='icon2' src='img/iconClassA.png'><span class='typea'>A-type main sequence star",
    "<img class='icon2' src='img/iconClassB.png'><span class='typeb'>B-type main sequence star"
]

var moonprohibition = [
10,
16,
8,
3,
1,
0,
0
]

var bgcolors = [
    "rgb(0,0,0)",
    "rgb(0,36,72)",
    "rgb(72,36,0)",

]

var surfaceliquidcolors = [
    "rgb(0,0,0)",
    "img/planeticons/waterOverlay",
    "img/planeticons/ammoniaOverlay",
    "img/planeticons/methaneOverlay",
    "img/planeticons/nitrogenOverlay"

]

var liquidcoveragefilenames = {
    0.02: "1.png",
    0.05: "1.png",
    0.1: "1.png",
    0.3: "2.png",
    0.7: "2.png",
    0.8: "2.png",
    0.9: "2.png",
    0.97: "3.png",
    1: "3.png",
    '-1': "3.png"
}

var liquidcoverageuwp = {
    0.02: "1",
    0.05: "1",
    0.1: "1",
    0.3: "3",
    0.7: "6",
    0.8: "8",
    0.9: "9",
    0.97: "A",
    1: "A",
    '-1': "A",
    0: "0",
    null: "0",
    '': "0",
    undefined: "0",
    NaN: "0",
}

var startypessizes = [
20,50,70,90,110,130,150
]

var startypescolors = [
    "#ffffff",
    "#ff9646",
    "#ffdcaa",
    "#ffffff",
    "#ffffff",
    "#ffffff",
    "#ffffff"
]

var startypesurls = [
    "img/staricons/typeb.png",
    "img/staricons/typem.png",
    "img/staricons/typek.png",
    "img/staricons/typeg.png",
    "img/staricons/typef.png",
    "img/staricons/typea.png",
    "img/staricons/typeb.png",
]

var startypesoutercolors = [
    "#5faf5f",
    "#7f0000",
    "#7f3f00",
    "#7f7f7f",
    "#7f8f9f",
    "#7f9fbf",
    "#9f9fff"
]


var planets = [];
function dice(n, s) {
    var tot=0; 
    for(var i=0; i < n; i++) {
        tot += Math.floor(prng() * s);
    } 
    return tot;
}
const CSVToArray = (data, delimiter = ',', omitFirstRow = false) =>
  data
    .slice(omitFirstRow ? data.indexOf('\n') + 1 : 0)
    .split('\n')
    .map(v => v.split(delimiter));



function placePlanets(starid,closecompanionpresent) {
    validorbits = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]; // All orbits start out blank.
    
    var o = 0; // This variable, o, is the orbit pointer, which is used to randomly select a position to try to place a planet.
    o=dice(1,2); // The first attempt to place a planet tries to place a Hot Jupiter.
    if(!dice(1,4)&&(!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<5)){ 
        // The Hot Jupiter will not generate if the primary system has a Tatooine-style binary (because the orbit would be unstable), or if a star in the system it's in is a white dwarf (because it would have been vaporized by the expanding star).
        var tmp1 = dice(1,12)+24; // The Hot Jupiter is a large planet, pulling from the upper 12 entries of the uberplanet size table. tmp1 here is the size index.
        planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, starid, null,null)) // Initialize some basic info about the planet:
        // the planet's ID (planets.length), its orbital position (o), its parent body (0-starid, a negative number, because it does not orbit another planet), 
        // the system it's in (starid, primary or secondary), its size (the value in the size table, ...sizes[tmp1]), the size index,
        // the "size class" (the 12-entry region of the size table its size is in), and the type of planet that it is (the value after planets.length).
        validorbits[o]=1;
        validorbits[o+1]=1;
            validorbits[o+2]=1;
            validorbits[o+3]=1;
            validorbits[o+4]=1;
            validorbits[o+5]=1;
            validorbits[o+6]=1;
            validorbits[o+7]=1;
            validorbits[o+8]=1;
            validorbits[o+9]=1;
            validorbits[o-1]=1;
        }
    for(let ag = 0; ag < dice(1,7)+1; ag++){
        o = dice(1,41)+1;
        if(validorbits[o] == 0 && dice(1,10)+5<o && dice(1,3)&&(o>10||!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<5)&&(!((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))))){
            var tmp1 = dice(1,8)+28;
            planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, starid, null,null))
            validorbits[o]=1;
            validorbits[o-1]=1;
            validorbits[o-2]=1;
            validorbits[o-3]=1;
            validorbits[o+1]=1;
            validorbits[o+2]=1;
            validorbits[o+3]=1;
            if((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))){
                validorbits[o-4]=1;
                validorbits[o+4]=1;
            }
        }
    }
    for(let ag = 0; ag < dice(1,10)+1; ag++){
        o = dice(1,41)+1;
        if(validorbits[o] == 0 && dice(1,42)<o&&(o>10||!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<5)&&(!((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))))){
            var tmp1 = dice(1,10)+18;
            planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, starid, null,null))
            validorbits[o]=1;
            validorbits[o-1]=1;
            validorbits[o-2]=1;
            validorbits[o-3]=1;
            validorbits[o+1]=1;
            validorbits[o+2]=1;
            validorbits[o+3]=1;
            if((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))){
                validorbits[o-4]=1;
                validorbits[o+4]=1;
            }
        }
    }
    for(let ag = 0; ag < dice(1,16)+1; ag++){
        o = dice(1,41)+1;
        if(validorbits[o] == 0 && dice(1,42)>o&&(o>10||!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<5)){
            var tmp1 = dice(1,6)+12;
            planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, starid, null,null))
            validorbits[o]=1;
            validorbits[o-1]=1;
            validorbits[o-2]=1;
            validorbits[o+1]=1;
            validorbits[o+2]=1;
            if((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))){
                validorbits[o-3]=1;
                validorbits[o+3]=1;
            }
        }
    }
    for(let ag = 0; ag < dice(1,28)+20; ag++){
        o = dice(1,41)+1;
        if(validorbits[o] == 0 && dice(1,42)>o&&(o>10||!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<7)){
            var tmp1 = dice(1,12);
            planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, starid, null,null))
            validorbits[o]=1;
            validorbits[o-1]=1;
            validorbits[o+1]=1;
            if((starid==2&&distantcompanionstartype==1)||(starid==1&&(primarystartype<=1&&closecompanionstartype<=1))){
                validorbits[o-2]=1;
                validorbits[o+2]=1;
            }
        }
    }
    for(let ag = 0; ag < dice(1,22)+20; ag++){
        o = dice(1,41)+1;
        if(validorbits[o] == 0 &&(o>10||!(starid==2&&distantcompanionstartype==0)&&!(starid==1&&(primarystartype==0||closecompanionstartype==0)))&&!(starid==1&&closecompanionpresent&&o<5)){
            var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        var tmp1 = dice(1,36);
                        planets.push(new Planet(unterplanetsizes[tmp1], null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, starid, null, beltl));
                    }
            validorbits[o]=1;
            validorbits[o-1]=1;
            validorbits[o+1]=1;
                validorbits[o-2]=1;
                validorbits[o+2]=1;
                validorbits[o-3]=1;
                validorbits[o+3]=1;
        }
    }
    /*while (o <= 41) {
        if(starid==1){
            if(!closecompanionpresent||o>6){
            if(ptag>(closecompanionpresent|0)){
                if(Math.random()>0.2 && o <= 12){
                if(dice(1,4)!=1 && ((primarystartype != 0 && closecompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    if(o <= 1 && Math.random()>=0.6 && primarystartype != 1){
                        var tmp1 = dice(1,12)+24;
                        planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, 1, null,null))
                        o += 12;
                    } else {
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 1, null,null));
                    if(primarystartype == 1 || closecompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
                    }

                    
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 1, null, beltl));
                    }
                    if(primarystartype == 1 || closecompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }     
            }
            else if(Math.random()>0.5 && o <= 22){
                if(dice(1,3)==1 && ((primarystartype != 0 && closecompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 1, null,null));
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 1, null, beltl));
                    }
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }     
            }
            else if((Math.random()>0.5 || o <= 19)&& o <= 30){
                if(dice(1,4)==1 && ((primarystartype != 0 && closecompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 1, null,null));
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 1, null, beltl));
                    }
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }   
            } else { {
                if(dice(1,6)==1 && ((primarystartype != 0 && closecompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 1, null,null));
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 1, null, beltl));
                    }
                    if(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent)){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }   
            }}
        }
            }
        } else {
            
            if(ptag>0){
            if(Math.random()>0.2 && o <= 12){
                if(dice(1,4)!=1 && ((distantcompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    if(o <= 1 && Math.random()>=0.6 && distantcompanionstartype != 1){
                        var tmp1 = dice(1,12)+24;
                        planets.push(new Planet(uberplanetsizes[tmp1], null, null, null, null, null, null, null, tmp1, 2, null, null, o, null, null, 0-starid, planets.length, 0, null, 2, null,null))
                        o += 12;
                    } else {
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 2, null,null));
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }}
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 2, null, beltl));
                    }
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }     
            } else if(Math.random()>0.5 && o <= 19){
                if(dice(1,3)==1 && ((distantcompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 2, null,null));
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 2, null, beltl));
                    }
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }     
            }
            else if((Math.random()>0.5 || o <= 19)&& o <= 30){
                if(dice(1,4)==1 && ((distantcompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 2, null,null));
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 2, null, beltl));
                    }
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }   
            } else { {
                if(dice(1,6)==1 && ((distantcompanionstartype != 0)|| o >= 10)){
                if(dice(1,6)!=1){
                    planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 0, null, 2, null,null));
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
                } else {
                    var beltl = dice(2, 6)-2;
                    for (var j=0; j < beltl; j++){
                        planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, o, null, null, 0-starid, planets.length, 1, null, 2, null, beltl));
                    }
                    if(distantcompanionstartype == 1){
                        o += 2;
                    } else {
                        o += 1;
                    }
            }
            }   
            }} 
        }}
        
        
        o++;
    }*/
}

function drawCircle(color,x,y,radius,ctx){
    ctx.fillStyle = color;
        ctx.beginPath();
        ctx.arc(x,y,radius,0,6.28);
        ctx.fill();
        ctx.closePath();
}

function image(img,x,y,scale,ctx){
    ctx.drawImage(img,x-(scale/2),y-(scale/2),scale,scale);
}
function image2(img,x,y,scale,ctx){
    let blah = document.createElement("img");
    blah.src=img;
    ctx.drawImage(blah,x-(scale/2),y-(scale/2),scale,scale);
}


function radius(planet){
    return planet.size/planet.density;
}

function displayRadius(planet,rexp,rscale){
    return Math.floor(radius(planet)**(rexp)*rscale*2);
}
function add_image_to_list(imglist, imgsrc) {
  var myimg = new Image();
  var myfulfill; var myreject;
  var mypromise = new Promise((ff, rj) => {myfulfill=ff;myreject=rj;});
  myimg.src = imgsrc;
  myimg.onload = function () {myfulfill(1);};
  myimg.onerror = myreject;
  imglist.push(myimg);
  return mypromise;
}
function add_image_to_list2(imglist, imgsrc) {
  var myimg = new Image();
  var myfulfill; var myreject;
  var mypromise = new Promise((ff, rj) => {myfulfill=ff;myreject=rj;});
  myimg.src = imgsrc;
  myimg.onload = function () {myfulfill(1);};
  myimg.onerror = myreject;
  imglist[imgsrc]=myimg;
  return mypromise;
}
function drawPlanet(planet,x,y,ctx,canvas){
    var imgs = [];
    let promises = [];
    var imgscounter = 0;
    var planetdiv = document.createElement("div")
    planetdiv.setAttribute("style","top:"+(y-displayRadius(planet,rexp,rscale))/13+"%;left:"+(x-displayRadius(planet,rexp,rscale))/37+"%;width:"+(displayRadius(planet,rexp,rscale)*2)/37+"%;height:"+(displayRadius(planet,rexp,rscale)*2)/13+"%;position:absolute;");
    planetdiv.setAttribute("name",JSON.stringify(planet));
    planetdiv.setAttribute("title",JSON.parse(planetdiv.getAttribute("name")).name);
    canvas.appendChild(planetdiv);
    if(planet.type==1){
        for(let aj = 0; aj < 100/(planet.beltlength**0.5); aj++){
            tmp9=Math.round(Math.random()*160);
            if(planet.orbit>20){
                drawCircle("#abcdef3f",Math.round(Math.random()*tmp9)-(tmp9/2)+(planet.orbit*80)+180,Math.round(Math.random()*1300),2,ctx);
            }else{
                drawCircle("#fedcba3f",Math.round(Math.random()*tmp9)-(tmp9/2)+(planet.orbit*80)+180,Math.round(Math.random()*1300),2,ctx);
            }
        
        }
    }

    if(planet.atmothickness>=3){
        if(planet.atmobasegas==2){
                    image(imageobjs["img/ATM_carbo.png"],x,y,displayRadius(planet,rexp,rscale)*3.3,ctx);
                }else{
                    image(imageobjs["img/ATM_nitro.png"],x,y,displayRadius(planet,rexp,rscale)*3.3,ctx);
                }
            }
            //image(compcolors[planet.composition],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            image(imageobjs[compcolors[planet.composition][planet.displayseed]],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            if(planet.composition<4){
            if(planet.geoactive==1){
                //image("img/planeticons/geoActiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                
                image(imageobjs["img/planeticons/geoActiveOverlay2.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }else{
                //image("img/planeticons/geoInactiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/geoInactiveOverlay.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
        }
        
        if(planet.life==2){
            if(planet.liquid==1){
                //image("img/planeticons/lifeOverlayWater.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayWater.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            if(planet.liquid==2){
                //image("img/planeticons/lifeOverlayAmmonia.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayAmmonia.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            if(planet.liquid==3){
                //image("img/planeticons/lifeOverlayMethanum.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayMethanum.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
                
            }
            if(planet.liquid>=1){
                //image(surfaceliquidcolors[planet.liquid]+liquidcoveragefilenames[planet.lcoverage]+"",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            
                image(imageobjs[surfaceliquidcolors[planet.liquid]+liquidcoveragefilenames[planet.lcoverage]+""],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            image(imageobjs["img/planeticons/shade.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            if(planet.composition<4){
                if(planet.temperature>=17){
                //image("img/planeticons/geoActiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/torridPlanetOverlay.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }else{
                //image("img/planeticons/geoInactiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            }
            if(planet.life>=1){
                image(imageobjs["img/planeticons/lifeIndicator.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            // wait until imgscounter = imgs.length
            // loop through imgs to draw the images to canvas
            
            // when all done:
            rscale=7;
            if(planet.rings){
                ctx.fillStyle=("rgb(127,127,127)")
                ctx.fillRect(x-displayRadius(planet,rexp,rscale)*2,y-displayRadius(planet,rexp,rscale)*0.1,displayRadius(planet,rexp,rscale)*4,displayRadius(planet,rexp,rscale)*0.2)
            }
            
}

async function loadSystem(){
    const selectedFile = document.getElementById("file").files[0];
    const systext = await selectedFile.text();
    systems = ArrayToSystems(CSVToArray(systext,",",true));
    for(let af = 0; af < systems.length; af++){
        refreshSystem(af);
    }
}

async function loadStartingSystem(){
    const selectedFile = await fetch("https://raw.githubusercontent.com/Vector-Graphics/walkersysgen/main/solarsystem.wssg").then(r => r.blob());
    const systext = await selectedFile.text();
    systems = ArrayToSystems(CSVToArray(systext,",",true));
    systems[0].primaryluminosity = 1;
    systems[0].closecompanionluminosity = 0;
    for(let af = 0; af < systems.length; af++){
        refreshSystem(af);
    }
}

function drawPlanet2(planet,x,y,ctx){
    var imgs = [];
    let promises = [];
    var imgscounter = 0;
    if(planet.atmothickness>=3){
                if(planet.atmobasegas==2){
                    image(imageobjs["img/ATM_carbo.png"],x,y,displayRadius(planet,rexp,rscale)*3.3,ctx);
                }else{
                    image(imageobjs["img/ATM_nitro.png"],x,y,displayRadius(planet,rexp,rscale)*3.3,ctx);
                }
            }
            //image(compcolors[planet.composition],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            image(imageobjs[compcolors[planet.composition][planet.displayseed]],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            if(planet.composition<4){
            if(planet.geoactive==1){
                //image("img/planeticons/geoActiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                
                image(imageobjs["img/planeticons/geoActiveOverlay2.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }else{
                //image("img/planeticons/geoInactiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/geoInactiveOverlay.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
        }
        
        if(planet.life==2){
            if(planet.liquid==1){
                //image("img/planeticons/lifeOverlayWater.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayWater.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            if(planet.liquid==2){
                //image("img/planeticons/lifeOverlayAmmonia.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayAmmonia.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            if(planet.liquid==3){
                //image("img/planeticons/lifeOverlayMethanum.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/lifeOverlayMethanum.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
                
            }
            if(planet.liquid>=1){
                //image(surfaceliquidcolors[planet.liquid]+liquidcoveragefilenames[planet.lcoverage]+"",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            
                image(imageobjs[surfaceliquidcolors[planet.liquid]+liquidcoveragefilenames[planet.lcoverage]+""],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }
            // wait until imgscounter = imgs.length
            // loop through imgs to draw the images to canvas
            image(imageobjs["img/planeticons/shade2.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            if(planet.composition<4){
                if(planet.temperature>=17){
                //image("img/planeticons/geoActiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                image(imageobjs["img/planeticons/torridPlanetOverlay.png"],x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }else{
                //image("img/planeticons/geoInactiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }}
            // when all done:
            
            rscale=21;
            if(planet.rings){
                ctx.fillStyle=("rgb(127,127,127)")
                ctx.fillRect(x-displayRadius(planet,rexp,rscale)*2,y-displayRadius(planet,rexp,rscale)*0.05,displayRadius(planet,rexp,rscale)*4,displayRadius(planet,rexp,rscale)*0.1)
            }
            
}

function drawPlanets(ctx,i,planets,canvas){
    if (planets[i].parentbody < 0 && planets[i].type==0){
       
            drawPlanet(planets[i],planets[i].orbit * 80+180,500,ctx,canvas)
        }
        

        if (planets[i].parentbody >=0 && planets[planets[i].parentbody].type==0){
            moonIndexIterator++;
            if(parentbodycheck != planets[i].parentbody){
                parentbodycheck = planets[i].parentbody;
                moonIndexIterator=0;
            }

            drawPlanet(planets[i],planets[i].orbit * 80+180,580+moonIndexIterator*50,ctx,canvas)

        }
        if ((planets[i].type == 1)){
            unterIndexIterator++;
            if(orbitcheck != planets[i].orbit){
                orbitcheck = planets[i].orbit;
                unterIndexIterator=0;
            }
            drawPlanet(planets[i],planets[i].orbit * 80+180,(500-(planets[i].beltlength-1)*25)+unterIndexIterator*50,ctx,canvas)
            
        }
        if ((planets[i].type == 2)){
            untermoonIndex++;
            if(orbitcheck2 != planets[i].orbit){
                orbitcheck2 = planets[i].orbit;
                untermoonIndex=0;
            }
            drawPlanet(planets[i],planets[i].orbit * 80+180,(500+(planets[planets[i].parentbody].beltlength-1)*25+100)+untermoonIndex*50,ctx,canvas)
            
        }
}
var parentbodycheck = 0;
    var rexp = 0.14
    var rscale = 10
    var moonIndexIterator = 0;
    var orbitcheck = -1;
    var orbitcheck2 = -1;
    var unterIndexIterator = 0;
    var unterIndexBuffer = 0;
    var untermoonIndex = 0;
    var unterplanetbelt = [];
function drawCanvas(planets,closecompanionpresent,distantcompanionpresent,primarystartype,closecompanionstartype,distantcompanionstartype,div){
    
    var canvas = document.createElement("canvas");
    var canvascontainer = document.createElement("div");
    canvascontainer.appendChild(canvas);
    canvascontainer.setAttribute("style","position:relative;width:100%;aspect-ratio:37/13;margin-bottom:0px;margin-top:0px;");
    var canvas2;
    canvas.setAttribute("width","3700");
    canvas.setAttribute("height","1300");
    canvas.classList.add("systemdisplay");
    var ctx = canvas.getContext("2d");
    ctx.imageSmoothingQuality="high";
    ctx.fillStyle = "rgb(0,255,0)";
    ctx.fillStyle = "rgb(0,255,0)";
    for(let aj = 0; aj < 100; aj++){
        drawCircle("#ffffff4f",Math.round(Math.random()*3700),Math.round(Math.random()*1300),2,ctx);
    }
    var imgs = [];
    let promises = [];
    var imgscounter = 0;

    
    ctx.fillStyle = "#ff45000f";
    for(var i = 0; i < 3; i++){
        //ctx.fillRect(i*40+90,0,40,650);
    }
    ctx.fillStyle = "#ffa8000f";
    for(var i = 3; i < 5; i++){
        //ctx.fillRect(i*40+90,0,40,650);
    }
    ctx.fillStyle = "#7fed560f";
    for(var i = 5; i < 11; i++){
        ctx.fillRect(i*80+180,0,80,1300);
    }
    ctx.fillStyle = "#51e9f40f";
    for(var i = 11; i < 18; i++){
        //ctx.fillRect(i*40+90,0,40,650);
    }
    ctx.fillStyle = "#368fe90f";
    for(var i = 18; i < 42; i++){
        //ctx.fillRect(i*40+90,0,40,650);
    }
    parentbodycheck = 0;
    rexp = 0.14
    rscale = 7
    moonIndexIterator = 0;
    orbitcheck = -1;
    orbitcheck2 = -1;
    unterIndexIterator = 0;
    unterIndexBuffer = 0;
    untermoonIndex = 0;
    unterplanetbelt = [];
    for(var i = 0; i < planets.length; i++) {
        if(planets[i].starsystem == 1){
        drawPlanets(ctx,i,planets,canvascontainer);
    }
   
    }
    if(!closecompanionpresent){
        image(imageobjs[startypesurls[primarystartype]],70-startypessizes[primarystartype],500,startypessizes[primarystartype]*8,ctx);
    } else{
        image(imageobjs[startypesurls[primarystartype]],70-startypessizes[primarystartype],250,startypessizes[primarystartype]*8,ctx);
        image(imageobjs[startypesurls[closecompanionstartype]],70-startypessizes[closecompanionstartype],750,startypessizes[closecompanionstartype]*8,ctx);
    }
    if(distantcompanionpresent){
        
        canvas2 = addline("",systemcontainerinterior,"canvas");
        var canvascontainer2 = document.createElement("div");
        canvascontainer2.appendChild(canvas2);
        canvascontainer2.setAttribute("style","position:relative;width:100%;aspect-ratio:37/13;margin-bottom:0px;margin-top:0px;");
        canvas2.setAttribute("width","3700");
    canvas2.setAttribute("height","1300");
    canvas2.classList.add("systemdisplay");
    var ctx2 = canvas2.getContext("2d");
    ctx2.fillStyle = "rgb(0,255,0)";
    for(let aj = 0; aj < 100; aj++){
        drawCircle("#ffffff4f",Math.round(Math.random()*3700),Math.round(Math.random()*1300),2,ctx2);
    }
    image(imageobjs[startypesurls[distantcompanionstartype]],70-startypessizes[distantcompanionstartype],500,startypessizes[distantcompanionstartype]*8,ctx2);


        ctx2.fillStyle = "#ff45000f";
    for(var i = 0; i < 3; i++){
        //ctx2.fillRect(i*40+90,0,40,650);
    }
    ctx2.fillStyle = "#ffa8000f";
    for(var i = 3; i < 5; i++){
        //ctx2.fillRect(i*40+90,0,40,650);
    }
    ctx2.fillStyle = "#7fed560f";
    for(var i = 5; i < 11; i++){
        ctx2.fillRect(i*80+180,0,80,1300);
    }
    ctx2.fillStyle = "#51e9f40f";
    for(var i = 11; i < 18; i++){
        //ctx2.fillRect(i*40+90,0,40,650);
    }
    ctx2.fillStyle = "#368fe90f";
    for(var i = 18; i < 42; i++){
        //ctx2.fillRect(i*40+90,0,40,650);
    }
    parentbodycheck = 0;
    moonIndexIterator = 0;
    orbitcheck = -1;
    orbitcheck2 = -1;
    unterIndexIterator = 0;
    unterIndexBuffer = 0;
    untermoonIndex = 0;
    unterplanetbelt = [];
    for(var i = 0; i < planets.length; i++) {
        if(planets[i].starsystem == 2){
        drawPlanets(ctx2,i,planets,canvascontainer2);
    }
    }
    }
    var canvases = document.createElement("div");
    canvases.appendChild(canvascontainer);
    if(canvas2){
        canvases.appendChild(canvascontainer2);
    }
    
    return canvases;
}
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
var hotjupiter = 0;
function generatePlanet(id) {
    var planetbuffer = planets[id];
    var orbit = planetbuffer.orbit;
    var type = planetbuffer.type;
    var parentbody = planetbuffer.parentbody;
    if(salibe){
        planetbuffer.name = generatePlanetName();
    } else {
        planetbuffer.name = "Salibe";
    }
    planetbuffer.displayseed=dice(1,6);
    if(type == 0) {
        if (planetbuffer.size==null){
            if (planetbuffer.starsystem == 1) {
            if (dice(1,15) <= planetbuffer.orbit - 1 && !(primarystartype == 1 && (closecompanionstartype == 1 || !closecompanionpresent))) {
            planetbuffer.sizeindex = dice(1,36);
            planetbuffer.size = uberplanetsizes[planetbuffer.sizeindex]
            } else {
            planetbuffer.sizeindex = dice(1,18);
            planetbuffer.size = uberplanetsizes[planetbuffer.sizeindex]
            }
            if (planetbuffer.starsystem == 2) {
            
            }
        } else {
            if (dice(1,15) <= planetbuffer.orbit - 1 && !(distantcompanionstartype == 1)) {
            planetbuffer.sizeindex = dice(1,36);
            planetbuffer.size = uberplanetsizes[planetbuffer.sizeindex]
            } else {
            planetbuffer.sizeindex = dice(1,18);
            planetbuffer.size = uberplanetsizes[planetbuffer.sizeindex]
        }
        } 
        }

        if(dice(1,6)==5||planetbuffer.size>=11){
            planetbuffer.rings=1;
        }
       
    } 
    if(type == 1) {
        planetbuffer.sizeindex = dice(1,36);
        planetbuffer.size = unterplanetsizes[planetbuffer.sizeindex]
        if(dice(1,2)==1){
            planetbuffer.rings=1;
        }
    }
    if(type == 2) {
        planetbuffer.sizeindex = dice(1,6);
        planetbuffer.size = untermoonsizes[planetbuffer.sizeindex]
    }
    if(type == 3) {
        planetbuffer.sizeindex = dice(1,12);
        planetbuffer.size = smubermoonsizes[planetbuffer.sizeindex]
    }
    if(type == 4) {
        planetbuffer.sizeindex = dice(1,12);
        planetbuffer.size = meubermoonsizes[planetbuffer.sizeindex]
    }
    if(type == 5) {
        planetbuffer.sizeindex = dice(1,18);
        planetbuffer.size = laubermoonsizes[planetbuffer.sizeindex]
    }
    if(type == 6) {
        planetbuffer.sizeindex = dice(1,18);
        planetbuffer.size = laubermoonsizes2[planetbuffer.sizeindex]
    }
    planetbuffer.sizeclass=Math.floor(planetbuffer.sizeindex/12);
    planetbuffer.moons=0;
    if((type == 0 || type == 1) && ((planetbuffer.starsystem==1&&(orbit>=moonprohibition[primarystartype]||orbit>=moonprohibition[closecompanionstartype]))||(planetbuffer.starsystem==2&&(orbit>=moonprohibition[distantcompanionstartype])))) {
        if(type == 1 && planetbuffer.sizeclass == 2){
            if (dice(1, 6)>=2) {
                planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, planetbuffer.orbit, null, null, planetbuffer.id, planets.length, 2, null, planetbuffer.starsystem, null,null,planetbuffer.moons));
                planetbuffer.moons++;
            }
        }
        if(type == 0 && planetbuffer.sizeclass == 0){
            for (var m = 0; m < planetbuffer.sizeindex; m++){
                if (dice(1, 24)>=23) {
                planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, planetbuffer.orbit, null, null, planetbuffer.id, planets.length, 3, null, planetbuffer.starsystem, null,null,planetbuffer.moons));
                planetbuffer.moons++;
            }
            }
            
        }
        if(type == 0 && planetbuffer.sizeclass == 1){
            for (var m = 0; m < planetbuffer.sizeindex; m++){
                if (dice(1, 15)>=14) {
                planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, planetbuffer.orbit, null, null, planetbuffer.id, planets.length, 4, null, planetbuffer.starsystem, null,null,planetbuffer.moons));
                planetbuffer.moons++;
            }
            }
            
        }
        if(type == 0 && planetbuffer.sizeclass == 2 && planetbuffer.size < 600){
            for (var m = 0; m < planetbuffer.sizeindex; m++){
                if (dice(1, 6)>=5) {
                planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, planetbuffer.orbit, null, null, planetbuffer.id, planets.length, 5, null, planetbuffer.starsystem, null,null,planetbuffer.moons));
                planetbuffer.moons++;
            }
            }
            
           
            }
            if(type == 0 && planetbuffer.size >= 600){
            for (var m = 0; m < planetbuffer.sizeindex; m++){
                if (dice(1, 6)>=5) {
                planets.push(new Planet(null, null, null, null, null, null, null, null, null, null, null, null, planetbuffer.orbit, null, null, planetbuffer.id, planets.length, 6, null, planetbuffer.starsystem, null,null,planetbuffer.moons));
                planetbuffer.moons++;
            }
        }   
            
        }

    }
    var compositionindex = dice(2,6)
    if(compositionindex <= 1) {
        planetbuffer.composition = 3;
        planetbuffer.density = 1.0+(dice(1,6)/10)
    } else if(compositionindex == 10) {
        planetbuffer.composition = 2;
        planetbuffer.density = 0.7+(dice(1,6)/10)
    } else if(orbit>17 && prng()>0.1) { // frostline
        planetbuffer.composition = 1;
        planetbuffer.density = 0.3+(dice(1,3)/10)
    } else {  
        planetbuffer.composition = 0;
        planetbuffer.density = 0.6+(dice(1,6)/10)
    }
    if((planetbuffer.starsystem == 1 && (primarystartype >0 || closecompanionstartype > 0))||(planetbuffer.starsystem == 2 && distantcompanionstartype > 0))
    {planetbuffer.basetemp = basetemptable[orbit]}
    else
    {planetbuffer.basetemp = 0}
    
    if (dice(1,12) >= (13 - Math.floor(planetbuffer.size))) {
        if ((planetbuffer.size <= 35 && prng() > 0.2) && planetbuffer.orbit > 20) {
            planetbuffer.composition = 4;
        } else {
            planetbuffer.composition = 5;
        }
        planetbuffer.density = 0.2;
        planetbuffer.atmobasegas = -1;
        planetbuffer.atmothickness = -1;
        planetbuffer.greenhouse = 0;
        planetbuffer.liquid = 0;
        planetbuffer.lcoverage = 0;
        
    } else {
        if ((planetbuffer.size >= 0.6 || 
        (planetbuffer.size >= 0.2 && dice(1,6) >= 1) || 
        (planetbuffer.size >= 0.06 && dice(1,6) >= 2) || 
        (planetbuffer.size >= 0.02 && dice(1,6) >= 3) || 
        (planetbuffer.size >= 0.006 && dice(1,6) >= 4) || 
        (planetbuffer.size >= 0.002 && dice(1,6) >= 4)) 
        && 
        (planetbuffer.orbit > 5 || prng() >= 0.5) && (planetbuffer.basetemp>0)) {
            if (planetbuffer.size <= 0.01 || (planetbuffer.size < 0.1 && planetbuffer.basetemp >= 5)) {
                planetbuffer.atmothickness = 1;
            } else if(planetbuffer.size <= 0.6) {
                planetbuffer.atmothickness = dice(1,6)+1;
            } else if(planetbuffer.size <= 3) {
                planetbuffer.atmothickness = dice(1,4)+3;
            } else {
                planetbuffer.atmothickness = dice(1,3)+4;
            }
        } else
        {
            planetbuffer.atmothickness = 0;
        }
        if ( planetbuffer.atmothickness > 0){
        planetbuffer.atmobasegas=1;
        if (planetbuffer.atmothickness >= 5){
                    planetbuffer.greenhouse = dice(1,5);
                    if(planetbuffer.greenhouse==0 && prng() >= 0.5){
                        planetbuffer.greenhouse = dice(1,5);
                    }
                }
                else if (planetbuffer.atmothickness >= 3){
                    planetbuffer.greenhouse = dice(1,planetbuffer.atmothickness);
                    if(planetbuffer.greenhouse==0 && prng() >= 0.5){
                        planetbuffer.greenhouse = dice(1,planetbuffer.atmothickness);
                    }
                } else {
                    planetbuffer.greenhouse = 0;
                }
                planetbuffer.temperature = greenhousetable[planetbuffer.basetemp][planetbuffer.greenhouse]
                var qrstuv = dice(1,7)+9;
        if(planetbuffer.temperature>(8+planetbuffer.atmothickness)&&planetbuffer.atmothickness >= 4){
            planetbuffer.atmobasegas=2;
            planetbuffer.atmothickness=6;
            planetbuffer.greenhouse=5;
        }

        if(planetbuffer.size<0.16&&age>1&&planetbuffer.atmothickness >= 2){
            planetbuffer.atmobasegas=2;
            planetbuffer.atmothickness=1;
            planetbuffer.greenhouse=0;
        }

           /* if (dice(1,10)>=planetbuffer.orbit && planetbuffer.basetemp > 5){
                planetbuffer.atmobasegas = 2;
                planetbuffer.greenhouse = planetbuffer.atmothickness;
                if (planetbuffer.greenhouse > 5) {
                    planetbuffer.greenhouse = 5;
                }
            }else{
                planetbuffer.atmobasegas = 1;
                if (planetbuffer.atmothickness >= 5){
                    planetbuffer.greenhouse = dice(1,5);
                    if(planetbuffer.greenhouse==0 && prng() >= 0.5){
                        planetbuffer.greenhouse = dice(1,5);
                    }
                }
                else if (planetbuffer.atmothickness >= 3){
                    planetbuffer.greenhouse = dice(1,planetbuffer.atmothickness);
                    if(planetbuffer.greenhouse==0 && prng() >= 0.5){
                        planetbuffer.greenhouse = dice(1,planetbuffer.atmothickness);
                    }
                } else {
                    planetbuffer.greenhouse = 0;
                }
            }*/
        } else {
            planetbuffer.atmobasegas = 0;
            planetbuffer.greenhouse = 0;
        }
    }
    planetbuffer.temperature = greenhousetable[planetbuffer.basetemp][planetbuffer.greenhouse]
    if (planetbuffer.temperature > 4 && planetbuffer.composition == 1) {
        planetbuffer.composition = 0;
        planetbuffer.density = (dice(1,6)/10) + 0.6
    }
    if (planetbuffer.atmothickness >= 0) {
        if (((9 <= planetbuffer.temperature) && (planetbuffer.temperature <= (8+planetbuffer.atmothickness))) && planetbuffer.atmothickness >= 3 && prng() > 0.33) {
            planetbuffer.liquid = 1;
        } else
        if (((((6 <= planetbuffer.temperature) && (planetbuffer.temperature <= 7)) && planetbuffer.atmothickness >= 3) || (((6 <= planetbuffer.temperature) && (planetbuffer.temperature <= 8)) && planetbuffer.atmothickness >= 4)) && prng() > 0.95) {
            planetbuffer.liquid = 2;
        } else
        if (((((2 <= planetbuffer.temperature) && (planetbuffer.temperature <= 3)) && planetbuffer.atmothickness >= 4) || (((2 <= planetbuffer.temperature) && (planetbuffer.temperature <= 5)) && planetbuffer.atmothickness >= 6)) && prng() > 0.95) {
            planetbuffer.liquid = 3;
        } else
        if ((((1 <= planetbuffer.temperature) && (planetbuffer.temperature <= 1)) && planetbuffer.atmothickness >= 3) && prng() > 0.95){
            planetbuffer.liquid = 4;
        } else {
            planetbuffer.liquid = 0;
        }
        if (planetbuffer.liquid >= 1) {
            planetbuffer.lcoverage = liquidcoveragetable[dice(1,12)];
        } else {
            planetbuffer.lcoverage = 0;
        }
    }

    if ((planetbuffer.size >= 1 ||
       (planetbuffer.size >= 0.5 && dice(1,6) >= 1) ||
       (planetbuffer.size >= 0.05 && dice(1,6) >= 2) ||
       (planetbuffer.size >= 0.005 && dice(1,6) >= 3) ||
       (planetbuffer.moons >= 0 && prng() >= 0.5) ||
       (planetbuffer.parentbody >= 0 && prng() >= 0.5)
        ) && planetbuffer.atmothickness >= 0) {
        planetbuffer.geoactive = true;
       } else {
        planetbuffer.geoactive = false;
       }
    
    if (planetbuffer.geoactive = true && dice(1,6)>0 && (planetbuffer.composition == 1 || (planetbuffer.liquid >= 1 && planetbuffer.liquid <= 3))) {
        if (dice(1,12)*0.3<=age-3){
            planetbuffer.life = 2;
            var xyz = prng();
            if(xyz<=1/1000 ){
                planetbuffer.civ = 1;
            }
            if(xyz>0.5){
                planetbuffer.civ = 2;
            }
        } else{
            planetbuffer.life = 1;
        }
    } else {
        planetbuffer.life = 0;
    }
    planetbuffer.oxygentag = 0;
    if (planetbuffer.liquid == 1 && planetbuffer.life == 2){
        planetbuffer.oxygentag = 1;
    }
    return planetbuffer;

    
}
var testPlanet;

var n;
var closecompanionstartype=-1;
var distantcompanionstartype=-1;
var closecompanionpresent;
var distantcompanionpresent;
var primarystartype=-1;
var primarystarname;
var closecompanionname;
var distantcompanionname;
var salibe;

function GenerateSystem(){
    var oolala=document.getElementById("seedinput");
    if((oolala.value >= 0 || oolala.value <= 0)&&oolala.value != ""){ // oolala.value is a number
    seed=oolala.value;
    } // else use random seed
    syscont=document.getElementsByClassName("systemcontainer")[0];
    systemcontainerinterior=document.createElement('div');
    systemcontainerinterior.classList.add("systemdisplay");
    inc = 0;
    maxinc = 1;
    while (syscont.hasChildNodes()) {
    syscont.removeChild(syscont.firstChild);
}
    systems = [];
    systemdivs = [];
    GenerateSystemLoopWrapper();
}

function refreshSystem(id){
    systemdivs[id]=(displaySystem(id));
    if(id>=page*10&&id<=(page+1)*10) {
        syscont=document.getElementsByClassName("systemcontainer")[0];
        while (syscont.hasChildNodes()) {
    syscont.removeChild(syscont.firstChild);
}
    systemcontainerinterior.innerHTML = "";
    document.getElementById("pagenumber").innerText = "Page "+(page+1);
    for(let ac = page*10; ac < (page*10)+10; ac++){
        if(systemdivs[ac]){
            systemcontainerinterior.appendChild(systemdivs[ac]);
        }

    }
    syscont.appendChild(systemcontainerinterior);
    }
}

function GenerateSystemLoopWrapper(){
    
    document.getElementsByClassName("progress")[0].textContent = ((inc+1)+"/"+maxinc);
        putGreeting();
        inc++;
        systemdivs.push(displaySystem(inc-1));
    if(inc < maxinc){
        setTimeout(GenerateSystemLoopWrapper,1);
        
    }else{
        page=0;
    document.getElementById("pagenumber").innerText = "Page "+(page+1);

    for(let ac = page*10; ac < (page*10)+10; ac++){
        if(systemdivs[ac]){
            systemcontainerinterior.appendChild(systemdivs[ac]);
        }
    }
    syscont.appendChild(systemcontainerinterior);
    }
    
}
var inc;
var maxinc;
var page = 0;
var systemdivs=[];
var syscont=0;
function GenerateSector(numberofsystems){
    var oolala=document.getElementById("seedinput");
    if((oolala.value >= 0 || oolala.value <= 0)&&oolala.value != ""){ // oolala.value is a number
    seed=oolala.value;
    } // else use random seed
    syscont=document.getElementsByClassName("systemcontainer")[0];
    systemcontainerinterior=document.createElement('div');
    systemcontainerinterior.classList.add("systemdisplay");
    inc = 0;
    maxinc = 5;
    if(numberofsystems==Number(numberofsystems)){
        numberofsystems = Math.abs(Math.ceil(numberofsystems));
        maxinc = numberofsystems;
    }
    
    syscont.innerHTML = "";
    systems = [];
    systemdivs = [];
    GenerateSystemLoopWrapper();

}

function incrementPages(){
    page++;
    syscont=document.getElementsByClassName("systemcontainer")[0];
    while (syscont.hasChildNodes()) {
    syscont.removeChild(syscont.firstChild);
}
while (systemcontainerinterior.hasChildNodes()) {
    systemcontainerinterior.removeChild(systemcontainerinterior.firstChild);
}
    document.getElementById("pagenumber").innerText = "Page "+(page+1);
    for(let ac = page*10; ac < (page*10)+10; ac++){
        if(systemdivs[ac]){
            systemcontainerinterior.appendChild(systemdivs[ac]);
        }

    }
    syscont.appendChild(systemcontainerinterior);
}

function decrementPages(){
    if(page>0){
        page--;
    }
    syscont=document.getElementsByClassName("systemcontainer")[0];
    while (syscont.hasChildNodes()) {
    syscont.removeChild(syscont.firstChild);
}
while (systemcontainerinterior.hasChildNodes()) {
    systemcontainerinterior.removeChild(systemcontainerinterior.firstChild);
}
    document.getElementById("pagenumber").innerText = "Page "+(page+1);
    for(let ac = page*10; ac < (page*10)+10; ac++){
        if(systemdivs[ac]){
            systemcontainerinterior.appendChild(systemdivs[ac]);
        }
    }
    syscont.appendChild(systemcontainerinterior);
}

var div;
var systemcontainerinterior;
var primaryname;
var closecompanionname;
var distantcompanionname;

var luminositymin= [
    1.7,
    0.001,
    0.1,
    0.6,
    1.5,
    5,
    30,
]

var luminositymax= [
    80,
    0.1,
    0.6,
    1.5,
    5,
    30,
    300,
]

var luminositymid= [
    8,
    0.01,
    0.3,
    1,
    3,
    10,
    100,
]

var primaryluminosity;
var closecompanionluminosity;
var distantcompanionluminosity;
function putGreeting() {
    seed=seed%491041798642919;
    var seedtemp = seed;
    salibe = dice(1,1000); // 1 in 1000 chance all planets will be named Salibe.
    systemcontainer=[]; // Initialize the system container.
    closecompanionstartype=-1; // By default, the close companion's star type is -1, indicating that it is not present.
    distantcompanionstartype=-1; // By default, the distant companion's star type is -1, indicating that it is not present.
    primarystartype=-1; // The primary star's star type is initialized at -1. This value is never meant to be seen in the final system as the primary star always exists.
    planets = []; // The system starts off with no planets.
    age = dice(1,36)*0.3+0.1; // Determine the age of the system: starting from 0.1, values incrementing by 0.3 up to 10.9. This is in billions of years.
    closecompanionpresent = false; // By default, the close companion is not present.
    distantcompanionpresent = false; // By default, the distant companion is not present.
    distantcompanionluminosity = 0; // The luminosity of nonexistent stars is 0.
    closecompanionluminosity = 0; // The luminosity of nonexistent stars is 0.
    if(dice(1,3)==2){ // 1 in 3 chance that there is a close companion.
        closecompanionpresent=true;
        closecompanionstartype=startypetable[dice(1,36)]; // Choose a star type using a d36 and the star type table.
        if(closecompanionstartype==1&&prng()>=0.5){
            closecompanionluminosity = prng()*0.001+0.0004 // About half of red dwarfs (star type 1) are very, very dim.
    }
        closecompanionluminosity = prng()*(luminositymax[closecompanionstartype]-luminositymin[closecompanionstartype])+luminositymin[closecompanionstartype]; // Choose a random value between the luminosity minimum and maximum for the star type.
        if(
            (closecompanionstartype==6 && age >= 0.5)||
            (closecompanionstartype==5 && age >= 3)||
            (closecompanionstartype==4 && age >= 8)
        ){
            closecompanionstartype = 0 // If the star is a B-type star (type 6) older than 0.5 billion years, an A-type star (type 5) older than 3 billion years, or an F-type star (type 4) older than 8 billion years, 
            //it has already exploded into a planetary nebula, and is now a white dwarf (type 0).
        }
    }
    if(dice(1,3)==2){ // 1 in 3 chance that there is a distant companion, meaning 5/9 chance that the system has at least 2 stars and 1 in 9 that it has all 3 possible stars.
        distantcompanionpresent=true; // Follow the same star type routine for the distant companion, if it is present.
        distantcompanionstartype=startypetable[dice(1,36)];
        distantcompanionluminosity = prng()*(luminositymax[distantcompanionstartype]-luminositymin[distantcompanionstartype])+luminositymin[distantcompanionstartype];
        if(distantcompanionstartype==1&&prng()>=0.5){
            distantcompanionluminosity = prng()*0.001+0.0004
    }
        if(
            (distantcompanionstartype==6 && age >= 0.5)||
            (distantcompanionstartype==5 && age >= 3)||
            (distantcompanionstartype==4 && age >= 8)
        ){
            distantcompanionstartype = 0
        }
        
    }
    primarystartype=startypetable[dice(1,36)]; // The primary star is always present, follow the same star type routine for the primary star.
    primaryluminosity = prng()*(luminositymax[primarystartype]-luminositymin[primarystartype])+luminositymin[primarystartype];
    if(primarystartype==1&&prng()>=0.5){
        primaryluminosity = prng()*0.001+0.0004
    }
    

        if(
            (primarystartype==6 && age >= 0.5)||
            (primarystartype==5 && age >= 3)||
            (primarystartype==4 && age >= 8)
        ){
            primarystartype = 0
        }
    
    
    placePlanets(1,closecompanionpresent); // Determine where the primary star's planets are located.
    if(distantcompanionpresent==true){
        
        placePlanets(2,closecompanionpresent); // Determine where the distant companion's planets are located. (The primary star's planets also orbit the close companion if it is present.)
    }
    // This generates the star's name.
    if(salibe){ // 1 in 1000 chance that all planets are named Salibe, as a reference to a feature in Universe Sandbox where certain randomly-generated names like Salibe recur.
        var tmp4 = generatePlanetName(); // Generate a random planet name, this is not significant but I might include it as a bonus in the doc.
    } else {
        var tmp4 = "Salibe";
    }
    
    if(closecompanionpresent){
        if(distantcompanionpresent){ // If all three stars are present, number them Aa, Ab, and B.
            primaryname=tmp4+" Aa";
            closecompanionname=tmp4+" Ab";
            distantcompanionname=tmp4+" B";
        } else {
            primaryname=tmp4+" A";
            closecompanionname=tmp4+" B";
        }
    } else {
        if(distantcompanionpresent){ // If only two stars are present, regardless of which stars they are, number them A and B.
            primaryname=tmp4+" A";
            distantcompanionname=tmp4+" B";
        } else {
            primaryname=tmp4; // If only one star exists, it does not get an ID, as that would be redundant.
        }
    }
    for (var k = 0; k < planets.length; k++){

        planets[k]=generatePlanet(k); // Generate the details of the planets.
        n = k;
    }
systems.push(new System(planets,primarystartype,closecompanionpresent,closecompanionstartype,distantcompanionpresent,distantcompanionstartype,age,age,primaryname,closecompanionname,distantcompanionname,primaryluminosity,closecompanionluminosity,distantcompanionluminosity,seedtemp))




}

function displaySystem(id){
    if(systems[id]){
        
        div=document.createElement('div');
div.classList.add("system");
addline(`Seed: `+systems[id].seed,div,"h3");
addline(`SYSTEM AGE: `+Number(systems[id].primaryage).toFixed(1),div,"h3");
addline('',div,"h3");
addline('PRIMARY STAR(S):',div,"h3");
addline(systems[id].primaryname+" - "+startypes[systems[id].primarystartype]+" (Main-sequence luminosity: "+Number(systems[id].primaryluminosity).toFixed(3)+"x solar luminosity)",div,"h3",true);
if(systems[id].closecompanionpresent == true || systems[id].closecompanionpresent == 1) {
    addline(systems[id].closecompanionname+" - "+startypes[systems[id].closecompanionstartype]+" (Main-sequence luminosity: "+Number(systems[id].closecompanionluminosity).toFixed(3)+"x solar luminosity)",div,"h3",true);

}


for (var q = 0; q < 42; q++) {
    for (var l = 0; l < systems[id].planets.length; l++) {
        if(systems[id].planets[l].orbit == q && systems[id].planets[l].starsystem==1) {
            generateplanetdesc(l, systems[id].planets,systems[id]); 
        }
    }
}

if(systems[id].distantcompanionpresent == true || systems[id].distantcompanionpresent == 1) {
    addline('',div,"h3");
    addline('SECONDARY STAR:',div,"h3");
    addline(systems[id].distantcompanionname+" - "+startypes[systems[id].distantcompanionstartype]+" (Main-sequence luminosity: "+Number(systems[id].distantcompanionluminosity).toFixed(3)+"x solar luminosity)",div,"h3",true);
}

for (var q = 0; q < 42; q++) {
    for (var l = 0; l < systems[id].planets.length; l++) {
        if(systems[id].planets[l].orbit == q && systems[id].planets[l].starsystem==2) {
           generateplanetdesc(l,systems[id].planets,systems[id]);
                

                

        }
    }
}
div2=document.createElement('div');
div2.appendChild(drawCanvas(systems[id].planets,systems[id].closecompanionpresent,systems[id].distantcompanionpresent,systems[id].primarystartype,systems[id].closecompanionstartype,systems[id].distantcompanionstartype));
div2.appendChild(div);
return div2;
    }
    
}
function generatePlanetName() {
    var tmp3;
    if(prng()>=0.5){
        if(prng()>=0.5){
            if(prng()>=0.3){
                tmp3 = capitalizeFirstLetter(syllable()+syllable()+nameends[dice(1,nameends.length)]);
    } else {
        tmp3 = capitalizeFirstLetter(syllable()+syllable()+syllable()+syllable()+nameends[dice(1,nameends.length)]);
    }
            
    } else {
        tmp3 = capitalizeFirstLetter(syllable()+syllable()+syllable()+nameends[dice(1,nameends.length)]);
    }
    } else {
        tmp3 = capitalizeFirstLetter(syllable()+syllable()+nameends[dice(1,nameends.length)]);
    }
    return tmp3;
}
function addline(text,parent= systemcontainer,style = "p",html=false) {
    var txt3 = document.createElement(style); 

    if(html){
        txt3.innerHTML = (text);
    }else{
        txt3.textContent = (text);

    }

    parent.appendChild(txt3);
    return(txt3);
}
function ArrayToPlanet(input,row) {
    var tmp6 = new Planet();
    var pa = input[row];
    tmp6.id=pa[idlocation];
    tmp6.starsystem=eval(pa[parentstarlocation]);
    tmp6.parentbody=eval(pa[parentbodylocation]);
    tmp6.orbit=eval(pa[orbitlocation]);
    tmp6.size=eval(pa[sizelocation]);
    tmp6.type=eval(pa[typelocation]);
    tmp6.sizeindex=1;
    tmp6.composition=eval(pa[compositionlocation]);
    tmp6.density=eval(pa[densitylocation]);
    tmp6.atmothickness=eval(pa[atmospherethicknesslocation]);
    tmp6.atmobasegas=eval(pa[atmobasegaslocation]);
    tmp6.oxygentag=eval(pa[oxygenlocation]);
    tmp6.liquid=eval(pa[liquidlocation]);
    tmp6.greenhouse=eval(pa[greenhouselocation]);
    tmp6.temperature=eval(pa[temperaturelocation]);
    tmp6.lcoverage=eval(pa[lcoveragelocation]);
    tmp6.life=eval(pa[lifelocation]);
    tmp6.moonnumber=eval(pa[moonindexlocation]);
    tmp6.rings=eval(pa[ringslocation]);
    tmp6.civ=eval(pa[civlocation]);
    tmp6.name=pa[namelocation];
    tmp6.beltlength=eval(pa[beltlengthlocation]);
    tmp6.basetemp=eval(pa[basetemplocation]);
    tmp6.displayseed=eval(pa[displayseedlocation]);
    tmp6.geoactive=eval(pa[geoactivelocation]);
    return tmp6;
}


function ArrayToSystems(input){
    var tmp7;
    var tempsystems = [];
    var workingsys = new System();
    for (let ae = 0; ae < input.length; ae++){
        if(tmp7 != input[ae][0]){
            tmp7 = input[ae][0];
            if(workingsys.planets){
                tempsystems.push(workingsys);
            }
            workingsys = new System();
            workingsys.planets = [];
            workingsys.primarystartype = eval(input[ae][primarystartypelocation]);
            workingsys.closecompanionpresent = eval(input[ae][closecompanionexistslocation].toLowerCase());
            workingsys.closecompanionstartype = eval(input[ae][closecompanionstartypelocation]);
            workingsys.distantcompanionpresent = eval(input[ae][distantcompanionexistslocation].toLowerCase());
            workingsys.distantcompanionstartype = eval(input[ae][distantcompanionstartypelocation]);
            workingsys.primaryname = input[ae][primarynamelocation];
            workingsys.closecompanionname = input[ae][closecompanionnamelocation];
            workingsys.distantcompanionname = input[ae][distantcompanionnamelocation];
            workingsys.primaryage = eval(input[ae][agelocation]);
            workingsys.secondaryage = eval(input[ae][agelocation]);
            workingsys.primaryluminosity = luminositymid[input[ae][primarystartypelocation]];
            workingsys.closecompanionluminosity = luminositymid[input[ae][closecompanionstartypelocation]];
            workingsys.distantcompanionluminosity = luminositymid[input[ae][distantcompanionstartypelocation]];
            if(input[ae][primaryluminositylocation]){
                workingsys.primaryluminosity = input[ae][primaryluminositylocation];
            }
            if(input[ae][closecompanionluminositylocation]){
                workingsys.closecompanionluminosity = input[ae][closecompanionluminositylocation];
            }
            if(input[ae][distantcompanionluminositylocation]){
                workingsys.distantcompanionluminosity = input[ae][distantcompanionluminositylocation];
            }
           
           
        } 
        workingsys.planets.push(ArrayToPlanet(input,ae))
    }
    tempsystems.push(workingsys);
    return tempsystems;
}
var sysindexlocation = 0;
var primarystartypelocation = 1;
var closecompanionexistslocation = 2;
var closecompanionstartypelocation = 3;
var distantcompanionexistslocation = 4;
var distantcompanionstartypelocation = 5;
var primarynamelocation = 6;
var closecompanionnamelocation = 7;
var distantcompanionnamelocation = 8;
var agelocation = 9;
var primaryluminositylocation = 10;
var closecompanionluminositylocation = 11;
var distantcompanionluminositylocation = 12;
var idlocation = 13;
var parentstarlocation = 15;
var parentbodylocation = 17;
var orbitlocation = 16;
var distancelocation = 14;
var sizelocation = 21;
var typelocation = 20;
var compositionlocation = 22;
var densitylocation = 23;
var atmospherethicknesslocation = 24;
var atmobasegaslocation = 25;
var oxygenlocation = 26;
var liquidlocation = 30;
var greenhouselocation = 27;
var temperaturelocation = 29;
var lcoveragelocation = 31;
var lifelocation = 34;
var moonindexlocation = 18;
var ringslocation = 32;
var civlocation = 35;
var namelocation = 14;
var beltlengthlocation = 19;
var basetemplocation = 28;
var displayseedlocation = 36;
var geoactivelocation = 33;


var csvheader= 
"system index,primary star type,close companion exists?,close companion star type,distant companion exists?,distant companion star type,"+
"primary name,close companion name,distant companion name,age,primary luminosity,close companion luminosity,distant companion luminosity,id,name,parent star(s),orbit index,parent body,moon index,belt length"+
",type,size,composition,density,atmosphere thickness,primary atmospheric gas,oxygen,greenhouse effect,base temperature,proper temperature,surface liquid,liquid coverage"+
",rings,geologically active,life,civilization,visual style,v2.0.0"
function csv(planet){
    /*return "" 
    + planet.id + "," 
    + planet.starsystem + ","  
    + planet.parentbody + "," 
    + planet.orbit + "," 
    + orbittable2[planet.orbit] + "," 
    + planet.size + "," 
    + planet.type + "," 
    + planet.sizeindex + "," 
    + planet.composition + ","
    + planet.density.toFixed(1) + ","
    + planet.atmothickness + "," 
    + planet.atmobasegas + "," 
    + planet.oxygentag + "," 
    + planet.liquid + "," 
    + planet.greenhouse + "," 
    + planet.temperature + "," 
    + planet.lcoverage + "," 
    + planet.life + "," 
    + ((planet.size/planet.density)**(0.3333)).toFixed(2) + "," 
    + (planet.size/((planet.size/planet.density)**0.6667)).toFixed(2) + "," 
    + planet.moonnumber + "," 
    + planet.rings + "," 
    + planet.civ + "," 
    + planet.name + "," 
    + planet.beltlength + "," 
    + planet.basetemp + "," 
    + planet.displayseed + "," 
    + planet.geoactive
    ;*/
    return "" 
    + planet.id + "," 
    + planet.name + "," 
    + planet.starsystem + ","  
    + planet.orbit + "," 
    + planet.parentbody + "," 
    + planet.moonnumber + "," 
    + planet.beltlength + "," 
    + planet.type + "," 
    + planet.size + "," 
    + planet.composition + ","
    + planet.density.toFixed(1) + ","
    + planet.atmothickness + "," 
    + planet.atmobasegas + "," 
    + planet.oxygentag + "," 
    + planet.greenhouse + "," 
    + planet.basetemp + "," 
    + planet.temperature + "," 
    + planet.liquid + "," 
    + planet.lcoverage + "," 
    + planet.rings + "," 
    + planet.geoactive + ","
    + planet.life + "," 
    + planet.civ + "," 
    
    + planet.displayseed + "," 
    ;
}

function systemcsv(system,ab){
    var systemcsvout = ``;
    for (let aa = 0; aa < system.planets.length; aa++){
        systemcsvout = systemcsvout + `
        ` + ab + `,` + system.primarystartype + `,` + system.closecompanionpresent + `,`+ system.closecompanionstartype + `,` + system.distantcompanionpresent + `,`+ system.distantcompanionstartype + `,`+ system.primaryname+  `,`+ system.closecompanionname+  `,`+ system.distantcompanionname+ ',' + system.primaryage.toFixed(1) + ',' + system.primaryluminosity+ ',' + system.closecompanionluminosity+ ',' + system.distantcompanionluminosity+ `,` + csv(system.planets[aa]);
    }
    return systemcsvout;
}
function fullcsv(systems){
    var fullcsvout = csvheader;
    for (let ab = 0; ab < systems.length; ab++){
        fullcsvout = fullcsvout + systemcsv(systems[ab],ab);
    } 
    return fullcsvout;
}

function displaycsv(csvin,div){
    div.empty();
    div.html("<p>" + csvin + "</p>");
}
function download(filename, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', filename);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}

function switchTheme() {
    if (document.documentElement.getAttribute('data-theme')=='light') {
        document.documentElement.setAttribute('data-theme', 'dark');
    }
    else {
        if (document.documentElement.getAttribute('data-theme')=='dark') {
        document.documentElement.setAttribute('data-theme', 'green');
    }
    else {
        if (document.documentElement.getAttribute('data-theme')=='green') {
        document.documentElement.setAttribute('data-theme', 'red');
    }
    else {
        if (document.documentElement.getAttribute('data-theme')=='red') {
        document.documentElement.setAttribute('data-theme', 'blue');
    }
    else {
        if (document.documentElement.getAttribute('data-theme')=='blue') {
        document.documentElement.setAttribute('data-theme', '2048');
    }
    else {
        if (document.documentElement.getAttribute('data-theme')=='2048') {
        document.documentElement.setAttribute('data-theme', 'midnight');
    }
    else {
        document.documentElement.setAttribute('data-theme', 'light');
    } 
    } 
    } 
    } 
    } 
    }    
}

function addDisplayLayer(planetview,imagesrc,sizemult,l,planets){
    var e = document.createElement("div");
    e.classList.add("planetdisplay");
    e.classList.add("planetoverlay");
        e.setAttribute("style","background-image:url('"+imagesrc+"');background-size:"+displayRadius(planets[l],0.14,21)*sizemult+"px;");
    planetview.appendChild(e);
}
function generateplanetdesc(l,planets,systemin) {
    addline(``,div,"p");
    addline(``,div, "hr");

    var planetview = document.createElement("div");
    planetview.classList.add("planetdisplay");
    planetview.classList.add("planetbg");
    if(planets[l].atmobasegas==2&&planets[l].atmothickness>=3){
        addDisplayLayer(planetview,'img/ATM_carbo.png',3.3,l,planets)
    }else if(planets[l].atmobasegas==1&&planets[l].atmothickness>=3){
        addDisplayLayer(planetview,'img/ATM_nitro.png',3.3,l,planets)
    }else;
    addDisplayLayer(planetview,compcolors[planets[l].composition][planets[l].displayseed],2,l,planets)
    if(planets[l].composition<4){
    if(planets[l].geoactive){
        addDisplayLayer(planetview,'img/planeticons/geoActiveOverlay2.png',2,l,planets)
    }else{
        addDisplayLayer(planetview,'img/planeticons/geoInactiveOverlay.png',2,l,planets)
    }}
    if(planets[l].life > 1){
        if(planets[l].liquid==1){
            addDisplayLayer(planetview,'img/planeticons/lifeOverlayWater.png',2,l,planets)
        }
        if(planets[l].liquid==2){
            addDisplayLayer(planetview,'img/planeticons/lifeOverlayAmmonia.png',2,l,planets)
        }
        if(planets[l].liquid==3){
            addDisplayLayer(planetview,'img/planeticons/lifeOverlayMethanum.png',2,l,planets)
        }
    }
    addDisplayLayer(planetview,surfaceliquidcolors[planets[l].liquid]+liquidcoveragefilenames[planets[l].lcoverage]+"",2,l,planets)
    addDisplayLayer(planetview,'img/planeticons/shade2.png',2,l,planets)

    if(planets[l].composition<4){
                if(planets[l].temperature>=17){
                //image("img/planeticons/geoActiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
                addDisplayLayer(planetview,'img/planeticons/torridPlanetOverlay.png',2,l,planets)
            }else{
                //image("img/planeticons/geoInactiveOverlay.png",x,y,displayRadius(planet,rexp,rscale)*2,ctx);
            }}
    if(planets[l].rings){
        addDisplayLayer(planetview,'img/planeticons/rings.png',4,l,planets)
    }



    div.appendChild(planetview);

    rscale=14;
    if(planets[l].parentbody<0){
        addline(parentbodynames2[planets[l].parentbody>=0] + typenames[planets[l].type]+` - `+planets[l].name+`:`,div,"h3",true) 
    }else{
        addline(parentbodynames2[planets[l].parentbody>=0] + typenames[planets[l].type]+` - `+planets[l].name+` (`+planets[planets[l].parentbody].name +` `+letters[planets[l].moonnumber]+`):`,div,"h3",true) 
    }
    var tmp2;
    if(planets[l].atmothickness == 0){
            tmp2 = "0";
        } else if (planets[l].atmothickness == 1){
            tmp2 = "1";
        } else 
    if(planets[l].oxygentag){
            if(planets[l].atmothickness == 2){
                tmp2 = "2";
            } else if (planets[l].atmothickness == 3){
                tmp2 = "5";
            }else if (planets[l].atmothickness == 4){
                tmp2 = "6";
            } else {
                tmp2 = "9";
            }
    } else {
        tmp2="A";
    }

    var tmp5 = "";
    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconMass.png"> Mass: ` + planets[l].size + `x the size of Earth` + "</p>";
    if(planets[l].starsystem==1){
        if(systemin.closecompanionpresent){
            if(primarystartype==0&&closecompanionstartype>0){
                tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconDistance.png"> Distance from star: ` + orbittable[planets[l].orbit] + " AU☉ (" + (orbittable2[planets[l].orbit]*Math.sqrt(systemin.closecompanionluminosity)).toFixed(2) + " AU) </p>";
            }else if(closecompanionstartype==0&&primarystartype>0){
                tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconDistance.png"> Distance from star: ` + orbittable[planets[l].orbit] + " AU☉ (" + (orbittable2[planets[l].orbit]*Math.sqrt(systemin.primaryluminosity)).toFixed(2) + " AU) </p>";
            }else{
                tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconDistance.png"> Distance from star: ` + orbittable[planets[l].orbit] + " AU☉ (" + (orbittable2[planets[l].orbit]*Math.sqrt(systemin.primaryluminosity+systemin.closecompanionluminosity)).toFixed(2) + " AU) </p>";
            }
        } else {
            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconDistance.png"> Distance from star: ` + orbittable[planets[l].orbit] + " AU☉ (" + (orbittable2[planets[l].orbit]*Math.sqrt(systemin.primaryluminosity)).toFixed(2) + " AU) </p>";
        }

       
    }else{
        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconDistance.png"> Distance from star: ` + orbittable[planets[l].orbit] + " AU☉ (" + (orbittable2[planets[l].orbit]*Math.sqrt(systemin.distantcompanionluminosity)).toFixed(2) + " AU) </p>";
    }
    
        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconTemperature.png"> Temperature: ` + temperaturenames[planets[l].temperature] + "</p>";
                if(planets[l].composition <= 3) {
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconComposition.png"> Composition: Primarily ` + compositionnames[planets[l].composition] + `, with a density of ` + Number(planets[l].density).toFixed(1) + `x that of the Earth, or `+ Number((planets[l].density*5.51)).toFixed(1) + " g/cm^3" + "</p>";
                    if(planets[l].atmobasegas == 2) {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconAtmosphere.png"> Atmosphere: `+atmothicknessnames[planets[l].atmothickness]+ `, <img class="icon" src="img/iconCarbonDioxide.png"><span class='orange'>carbon dioxide</span>` + lifenames_atmo[planets[l].oxygentag] + vapornames[planets[l].liquid] + greenhousenames[planets[l].greenhouse] + ` greenhouse effect` + "</p>";
                    } else if(planets[l].atmothickness>0) {
                        if(planets[l].greenhouse > 0 && planets[l].basetemp > 5) {
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconAtmosphere.png"> Atmosphere: `+atmothicknessnames[planets[l].atmothickness]+ `, <img class="icon" src="img/iconNitrogen.png"><span class='lightblue'>nitrogen</span>` + lifenames_atmo[planets[l].oxygentag] + vapornames[planets[l].liquid] + ', carbon dioxide' + greenhousenames[planets[l].greenhouse] + ` greenhouse effect` + "</p>";
                        } else {
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconAtmosphere.png"> Atmosphere: `+atmothicknessnames[planets[l].atmothickness]+ `, <img class="icon" src="img/iconNitrogen.png"><span class='lightblue'>nitrogen</span>` + lifenames_atmo[planets[l].oxygentag] + vapornames[planets[l].liquid] + greenhousenames[planets[l].greenhouse] + ` greenhouse effect` + "</p>";
                        }
                    } else {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconAtmosphere.png"> Atmosphere: none` + "</p>";
                    }
                    
                    if(planets[l].liquid > 0){
                        if(planets[l].lcoverage < -0.5){
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconLiquid.png"> Surface liquid: ` + liquidnames[planets[l].liquid] + " (" + Math.abs(planets[l].lcoverage*100) + "% coverage, superoceanic)" + "</p>";
                        }else{
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconLiquid.png"> Surface liquid: ` + liquidnames[planets[l].liquid] + " (" + Math.abs(planets[l].lcoverage*100) + "% coverage)" + "</p>";
                        }
                
                    
                    } else {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconLiquid.png"> Surface liquid: none` + "</p>";
                    }

                    if(planets[l].geoactive) {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconActivity.png"> Geologically active: <span class='orange'>yes</span>` + "</p>";
                    }
                    if(!planets[l].geoactive) {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconActivity.png"> Geologically active: no` + "</p>";
                    }
                    
                        if(planets[l].life == 0){
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconLife.png"> Life: none` + "</p>";
                        }else{
                            tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconLife.png"> Life: ` + spancolorslife[planets[l].liquid]+ lifenames[planets[l].life] +" "+ liquidnameslife[planets[l].liquid]+"</span>" + "</p>";
                        }

                    

                    
                    
                
                
                } else {
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconComposition.png"> Composition: A` + compositionnames[planets[l].composition] + ` with a density of ` + planets[l].density.toFixed(1) + `x that of the Earth, or `+ (planets[l].density*5.51).toFixed(1) + " g/cm^3" + "</p>";
                }
                if(planets[l].parentbody < 0){
                    if(planets[l].starsystem == 1) {
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconSystem.png"> Primary system` + "</p>";
                    } else{
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconSystem.png"> Secondary system` + "</p>";
                    }
                   
                } else {
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconSystem.png"> Orbits: ` + planets[planets[l].parentbody].name + "</p>";
                }
                tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconRadius.png"> Radius: ` + Number(((planets[l].size/planets[l].density)**(0.3333))).toFixed(2) + ` Earth radii (`+ Number((((planets[l].size/planets[l].density)**(0.3333))*6371)).toFixed(0) +` km)` + "</p>";
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconGravity.png"> Surface gravity: ` + Number((planets[l].size/((planets[l].size/planets[l].density)**0.6667))).toFixed(2) + ` g` + "</p>";
                if(planets[l].rings){
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconRings.png"> Rings: <span class='yellow'>Yes</span>` + "</p>";
                }else{
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconRings.png"> Rings: No` + "</p>";
                }

                tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconUWP.png"> Traveller profile: `+planets[l].name+` xxyy q` + hexadecimalDigits[Math.floor(Math.min(Number(((planets[l].size/planets[l].density)**(0.3333))).toFixed(2)*8,15))] + tmp2 +  liquidcoverageuwp[planets[l].lcoverage]+"pgl-t b tc tc z" + "</p>";
                if(planets[l].civ){
                    if(planets[l].civ == 2){
                    tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconCivilization.png"> <span class='lightblue'>Is a homeworld (demi-civilization)</span>`+"</p>";
                    } else{
                        tmp5 = tmp5 + "<p>"+ parentbodynames[planets[l].parentbody>=0] + `<img class="icon whiteicon" src="img/iconCivilization.png"> <span class='blue'>Is a homeworld (technological civilization)</span>`+"</p>";
                    }
                    
                }

                tmp5 = tmp5 + "</br>"
                addline(tmp5,div,"div",true);
                var tmp5 = "";
                tmp5 = tmp5 + '<p>Habitability results: HABITABLE '
                if((planets[l].composition == 1 && planets[l].geoactive) || (planets[l].liquid > 0 && planets[l].liquid < 4)){
                     if ((planets[l].liquid > 1)){
                        tmp5 = tmp5 + "(...that ain't lookin like water to me) </p>"
                    } else if((planets[l].composition == 1)){
                        tmp5 = tmp5 + "(...but it's kinda dark) </p>"
                    } else if ((planets[l].lcoverage == 0)){
                        tmp5 = tmp5 + "(...something weird happened here) </p>"
                    } else if ((!planets[l].oxygentag)){
                        tmp5 = tmp5 + "(...the lack of oxygen isn't all that important) </p>"
                    } else if ((planets[l].life < 2)){
                        tmp5 = tmp5 + "(...no complex life already present, though) </p>"
                    } else {
                        tmp5 = tmp5 + "(...minsharic planets are rather boring, aren't they?) </p>"
                    }
                } else {
                    tmp5 = tmp5 + "(...if you're brave enough) </p>"
                }
                tmp5 = tmp5 + '<p>Other scan information : </p>'
                if(planets[l].composition == 1){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>Scans show that the surface is cold and icy'
                    }else{  
                        tmp5 = tmp5 + '<p>Scans show that the planet is mainly made of ice'
                    }
                    
                        if(planets[l].displayseed > 0 && planets[l].displayseed < 5){
                            tmp5 = tmp5 + ', with sediments of reddish-brown organic compounds having accumulated on the surface due to reactions with high-energy radiation from the star. '
                        } else {
                            tmp5 = tmp5 + '. '
                        }
                        if(planets[l].geoactive){
                            tmp5 = tmp5 + ' Occasionally, cryovolcanoes spew out water and other ices, which cool and keep the surface of the planet fresh. Due to this, we know that an ocean of liquid water exists under the surface of the planet.'
                        } else {
                            tmp5 = tmp5 + ' Craters dot the surface, which were formed when asteroids, comets, or meteoroids crashed into the planet.'
                        }
                } else if(planets[l].composition == 2){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>Scans show that the surface rocks are composed of carbon compounds like graphite. '
                    }else{  
                        tmp5 = tmp5 + '<p>Scans show a high presence of carbon-based compounds on the surface.'
                    }
                    
                        if(planets[l].geoactive){
                            tmp5 = tmp5 + ' Large, rough diamonds jut out from the ground, forged deep in the mantle and brought up to the surface via volcanic eruptions. '
                        } else {
                            if((planets[l].temperature + planets[l].displayseed)/2==Math.round((planets[l].temperature + planets[l].displayseed)/2)){
                                tmp5 = tmp5 + ' Craters dot the surface, scars of impacts with comets, meteorites, and other space debris.'
                            }else{
                                tmp5 = tmp5 + ' This planet is pockmarked with clearly visible craters, due to asteroid impacts.'
                            }
                            
                        }
                } else if(planets[l].composition == 3){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>Scans show that the planet contains a very large amount of iron and other metallic elements, and would be a prime site for mining.'
                    }else{  
                        tmp5 = tmp5 + '<p>Scans show that the interior of the planet is very rich in metals.'
                    }
                   
                        if(planets[l].geoactive){
                            tmp5 = tmp5 + ' Occasionally, volcanoes erupt and bring magma to the surface, which cools and keeps the surface of the planet fresh and relatively devoid of craters.'
                        } else {
                            tmp5 = tmp5 + ' There are many craters on the surface, which were created by impacts with comets or asteroids.'
                        }
                } else if(planets[l].composition == 5){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>This planet is a stormy gas giant, with no landable surface. (I mean, if you REALLY wanted to, you could try landing here, but neither you nor your ship would survive.) Instead, you might want to check out any satellites that may exist orbiting this planet.'
                    }else{  
                        tmp5 = tmp5 + '<p>This planet is a gas giant without an acccessible surface layer. (There`s probably a surface down there SOMEWHERE, but it`s not like it`s safe.) Instead, you might want to check out any of this planet`s satellite planets, if they exist.'
                    }
                    
                } else if(planets[l].composition == 4){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>This planet is a windy ice giant, with no landable surface. (I mean, there is a surface EVENTUALLY, but it isn`t really reachable safely. You might encounter some freaky supercritical oceans, though, if you manage to get that far.) Go check out its major moons instead, if it has any.'
                    }else{  
                        tmp5 = tmp5 + '<p>This planet has a very thick hydrogen and methane atmosphere over a strange ocean of supercritical water. I can`t see any kind of surface to it, though. An ice giant for sure. (There probably is one if you go down far enough, but I wouldn`t count on surviving the trip there.) Ice giants tend to have plenty of major moons to explore, though.'
                    }
                    
                } else if(planets[l].composition == 0){
                    if(planets[l].displayseed >= 3){
                        tmp5 = tmp5 + '<p>Scans show that this planet is primarily made of silicate rocks, with a possible iron core.'
                    }else{  
                        tmp5 = tmp5 + '<p>Scans indicate the presence of a very thick, silicate mantle.'
                    }
                        if(planets[l].geoactive){
                            tmp5 = tmp5 + ' Occasionally, volcanoes spew out molten rock, which cools and keeps the surface of the planet fresh and relatively devoid of craters.'
                        } else {
                            if((planets[l].temperature + planets[l].displayseed)/2==Math.round((planets[l].temperature + planets[l].displayseed)/2)){
                                tmp5 = tmp5 + ' This planet has several large impact craters. And many smaller ones.'
                            }else{
                                tmp5 = tmp5 + ' The surface is covered with numerous craters and basins, formed from impacts by comets or other space debris.'
                            }
                        }
                } 
                if(planets[l].composition <= 3){

                
                if(planets[l].lcoverage != 0){
                    if(planets[l].lcoverage == -1){
                        tmp5 = tmp5 + ' The planet is covered in a massive, ridiculously deep planetwide ocean of ' + liquidnames2[planets[l].liquid] + '. In fact, it`s so deep that I doubt there`s any dry land at all!'
                        if(planets[l].atmothickness >= 4){
                            tmp5 = tmp5 + " I can't really tell though, due to the seeming 'planetwide storm' that exists here interfering with the scans."
                        }
                    } else {
                        if(planets[l].lcoverage > 0.95){
                            if(planets[l].geoactive){
                            tmp5 = tmp5 + ' The planet is covered in a massive ocean of ' + liquidnames2[planets[l].liquid] + ', with various volcanic islands dotted around, breaking up the endless expanse of ocean.'

                            } else {
                                tmp5 = tmp5 + ' The planet is almost entirely covered in a massive ocean of ' + liquidnames2[planets[l].liquid] + '.'
                            }
                            if(planets[l].atmothickness >= 4){
                            tmp5 = tmp5 + " There is a seeming 'planetwide storm' that exists here interfering with the scans."
                        }
                }   else if(planets[l].lcoverage > 0.25){
                    tmp5 = tmp5 + ' The planet has several large continents, separated by large seas of ' + liquidnames2[planets[l].liquid] + '.'
                } else {
                    tmp5 = tmp5 + ' The planet has small seas of ' + liquidnames2[planets[l].liquid] + '.'
                }
                    
            }} 
            if(planets[l].atmothickness > 0){
                if(planets[l].atmothickness/2 + planets[l].atmobasegas == Math.round(planets[l].atmothickness/2 + planets[l].atmobasegas)){
                if(planets[l].atmobasegas == 2){
                    tmp5 = tmp5 + ' This planet has a ' + atmothicknessnames2[planets[l].atmothickness] + ' atmosphere composed of primarily carbon dioxide'
                }else{
                    tmp5 = tmp5 + ' This world has a ' + atmothicknessnames2[planets[l].atmothickness] + ' atmosphere composed of mostly nitrogen'
                }
            } else {
                if(planets[l].atmobasegas == 2){
                    tmp5 = tmp5 + ' This world posesses a ' + atmothicknessnames2[planets[l].atmothickness] + ' atmosphere primarily made of gaseous carbon dioxide'
                }else{
                    tmp5 = tmp5 + ' This planet has a ' + atmothicknessnames2[planets[l].atmothickness] + ' atmosphere mainly made up of nitrogen'
                }
            }
                if(planets[l].oxygentag){
                    if((planets[l].civ + planets[l].greenhouse)/2 == Math.round((planets[l].civ + planets[l].greenhouse)/2)){
                        tmp5 = tmp5 + '. The atmosphere has a large proportion of oxygen as well, making it suitable to light fires'
                    }else{
                        tmp5 = tmp5 + '. The atmosphere also contains large amounts of oxygen, which I don`t really see the significance of'
                    }

                    
                    
                }
                if(planets[l].lcoverage != 0){
                    tmp5 = tmp5 + ', and the oceans maintain a stable ' + liquidnames2[planets[l].liquid] + " cycle in the atmosphere, creating clouds and rain."
                } else {
                    tmp5 = tmp5 + '.'
                }

            }else{
                tmp5 = tmp5 + ' This planet has no atmosphere.'
            }
            
            if(planets[l].greenhouse > 0){
                tmp5 = tmp5 + " The planet's atmosphere traps incoming heat from the sun, warming up the planet"
                if(planets[l].greenhouse >= 5){
                tmp5 = tmp5 + ". In fact, this 'greenhouse effect' is so strong that it heats the planet up to " + temperaturenames2[planets[l].temperature] + "!"
            } else {
                tmp5 = tmp5 + " to " + temperaturenames2[planets[l].temperature] + "."
            }
            } else {
                if (planets[l].atmothickness > 0){
                    tmp5 = tmp5 + " The planet's atmosphere has a negligible effect on its average temperature, which sits at " + temperaturenames2[planets[l].temperature] + "."
                }else {
                    tmp5 = tmp5 + " The planet's average temperature sits at " + temperaturenames2[planets[l].temperature] + ", but experiences wild temperature swings due to the lack of an atmosphere to retain heat."
                }
                
            }
            if(planets[l].temperature >= 17){
                tmp5 = tmp5 + " This planet is so hot that it glows, like metal being heated up in a blacksmithing forge."
            }
            if(planets[l].life){
                if(planets[l].life == 1){
                    if(planets[l].lcoverage == 0){
                    tmp5 = tmp5 + " This planet  has simple life in its subsurface ocean, a biosphere powered by geothermal activity alone."
                } else if(planets[l].composition == 1 && planets[l].geoactive){
                    tmp5 = tmp5 + " This planet has simple life in its subsurface ocean, a biosphere powered by geothermal activity alone. It also has life on its surface, which is based on " + liquidnames2[planets[l].liquid] + "."
                } else {
                    tmp5 = tmp5 + " This planet  has simple life on its surface, which is based on " + liquidnames2[planets[l].liquid] + "."
                }
                }
                if(planets[l].life == 2){
                    if(planets[l].lcoverage == 0){
                    tmp5 = tmp5 + " This planet contains advanced life in its subsurface ocean, a biosphere powered by geothermal activity alone."
                } else if(planets[l].composition == 1 && planets[l].geoactive){
                    tmp5 = tmp5 + " This planet contains advanced life in its subsurface ocean, a biosphere powered by geothermal activity alone. It also has life on its surface, which is based on " + liquidnames2[planets[l].liquid] + "."
                } else {
                    tmp5 = tmp5 + " This planet has advanced life on its surface, which is based on " + liquidnames2[planets[l].liquid] + "."
                }
                }
                
            }
        } if(planets[l].parentbody >= 1){
            if(planets[l].displayseed <= 3){
                tmp5 = tmp5 + " This is a moon of another planet, and is tidally locked to the planet which it orbits"
            } else {
                tmp5 = tmp5 + " This satellite planet is tidally locked to the planet it orbits"
            }
                    
                    if(planets[planets[l].parentbody].composition >= 4){
                        if(planets[l].displayseed/2 == Math.round(planets[l].displayseed/2)){
                tmp5 = tmp5 + ", meaning one side has a much cooler view of the night sky than the other side."
            } else {
                tmp5 = tmp5 + ", meaning one side always faces the parent planet, and one side always faces away from it."
            }
                        if(planets[l].atmothickness >= 2) {
                            tmp5 = tmp5 + " In fact, the jovian appears so large and bright that it brightens the night sky on that side to a dim twilight."
                        }
                    } else {
                        tmp5 = tmp5 + "."
                    }
                
            }
                        if(planets[l].rings){
                            if((planets[l].composition + planets[l].displayseed)/2 == Math.round((planets[l].composition + planets[l].displayseed)/2)){
                                tmp5 = tmp5 + " Additionally, this planet has a ring system, a remnant of an asteroid or small moon that wandered too close to it and got torn apart by tidal forces."
                                if(planets[l].composition <= 3){
                    tmp5 = tmp5 + " I bet it looks gorgeous from the surface, but it sure will make navigating around the planet a pain."
                } else {
                    
                }
                            } else {
                                tmp5 = tmp5 + " Also, this planet has rings, which were created as an asteroid or comet got too close to the planet and got torn apart by tidal forces."
                                if(planets[l].composition <= 3){
                    tmp5 = tmp5 + " I bet they look rather beautiful from the surface, but it will make navigating around the planet rather annoying."
                } else {
                    
                }
                            }
                    

            }
                tmp5 = tmp5 + '</p>'

                addline(tmp5,div,"div",true).classList.add("planetscan")


            


                
                
}
var seed = Math.floor(Math.random()*441041798642919);
function prng() {
    seed = ((seed*seed*seed*seed*seed*seed)+249254546412641)%491041798642919;
    //return seed/491041798642919;
    return seed/491041798642919;
    
}

function Initialize(){

    document.documentElement.setAttribute('data-theme', 'dark');
    systemcontainerinterior=document.createElement('div');
systemcontainerinterior.classList.add("systemcontainerinterior")
    ".systemcontainer".innerHTML = "";
    var promises2 = [];
    for(let ak = 0; ak < imgsrcs.length; ak++){
        promises2.push(add_image_to_list2(imageobjs,imgsrcs[ak]));
    }
    

    Promise.allSettled(promises2).then(loadStartingSystem());
    
/*    systems = [];
    systemcontainer=[];
    closecompanionstartype=-1;
    distantcompanionstartype=-1;
    primarystartype=3;
    
    planets = [];
    age = 4.6;
    closecompanionpresent = false;
    distantcompanionpresent = false;
    planets.push(new Planet(0.06,3,1,0,0,0,0,0,1,0,0,0,3,13,13,-1,0,0,0,1,0,-1,-1,3,0,0,"Mercury"));
    planets.push(new Planet(0.85,0,0.9,2,6,5,0,0,9,0,1,0,6,9,16,-1,1,0,0,1,0,-1,-1,5,0,0,"Venus"));
    planets.push(new Planet(1,0,1,1,4,2,1,0.7,10,0,1,2,9,8,9,-1,2,0,1,1,2,-1,-1,5,0,1,"Earth"));
    planets.push(new Planet(0.1,0,0.7,2,1,0,0,0,2,0,1,0,12,6,6,-1,3,0,0,1,0,-1,-1,4,0,0,"Mars"));
    planets.push(new Planet(0.00016,1,0.4,0,0,0,0,0,1,0,0,0,17,4,4,-1,4,1,0,1,0,1,-1,4,0,0,"Ceres"));
    planets.push(new Planet(300,5,0.2,0,0,0,0,0,1,0,0,0,22,3,3,-1,5,0,0,1,0,-1,-1,2,1,0,"Jupiter"));
    planets.push(new Planet(100,5,0.2,0,0,0,0,0,1,0,0,0,28,1,1,-1,6,0,0,1,0,-1,-1,3,1,0,"Saturn"));
    planets.push(new Planet(14,4,0.2,0,0,0,0,0,1,0,0,0,33,0,0,-1,7,0,0,1,0,-1,-1,5,1,0,"Uranus"));
    planets.push(new Planet(17,4,0.2,0,0,0,0,0,1,0,0,0,36,0,0,-1,8,0,0,1,0,-1,-1,1,1,0,"Neptune"));
    planets.push(new Planet(0.002,1,0.4,1,1,0,0,0,1,0,1,2,39,0,0,-1,9,1,0,1,0,10,-1,3,0,0,"Pluto"));
    planets.push(new Planet(0.003,1,0.5,1,1,0,0,0,1,0,1,2,39,0,0,-1,10,1,0,1,0,10,-1,4,0,0,"Eris"));
    planets.push(new Planet(0.0006,1,0.5,1,1,0,0,0,1,0,1,2,39,0,0,-1,11,1,0,1,0,10,-1,1,0,0,"Haumea"));
    planets.push(new Planet(0.0005,1,0.3,1,1,0,0,0,1,0,1,2,39,0,0,-1,12,1,0,1,0,10,-1,2,0,0,"Makemake"));
    planets.push(new Planet(0.0003,1,0.3,1,1,0,0,0,1,0,1,2,39,0,0,-1,13,1,0,1,0,10,-1,4,0,0,"Gonggong"));
    planets.push(new Planet(0.0002,1,0.4,1,1,0,0,0,1,0,1,1,39,0,0,-1,14,1,0,1,0,10,-1,5,0,0,"Quaoar"));
    planets.push(new Planet(0.00015,1,0.4,1,1,0,0,0,1,0,1,0,39,0,0,-1,15,1,0,1,0,10,-1,2,0,0,"Sedna"));
    planets.push(new Planet(0.00008,1,0.4,1,1,0,0,0,1,0,0,0,39,0,0,-1,16,1,0,1,0,10,-1,0,0,0,"Mandos"));
    planets.push(new Planet(0.0001,1,0.3,1,1,0,0,0,1,0,0,0,39,0,0,-1,17,1,0,1,0,10,-1,3,0,0,"Orcus"));
    planets.push(new Planet(0.0001,1,0.3,1,1,0,0,0,1,0,0,0,39,0,0,-1,18,1,0,1,0,10,-1,2,0,0,"Salacia"));
    planets.push(new Planet(0.2,1,0.4,1,6,4,0,0,2,0,1,2,41,0,1,-1,19,0,0,1,0,-1,-1,0,0,0,"Khione (hypothetical)"));
    planets.push(new Planet(0.01,0,0.6,0,0,0,0,0,2,0,0,0,9,8,8,2,20,3,0,1,0,-1,0,3,0,0,"Luna"));
    planets.push(new Planet(0.015,0,0.7,0,0,0,0,0,2,0,1,0,22,3,3,5,21,5,0,1,0,-1,0,5,0,0,"Io"));
    planets.push(new Planet(0.008,1,0.5,0,0,0,0,0,2,0,1,2,22,3,3,5,22,5,0,1,0,-1,1,4,0,0,"Europa"));
    planets.push(new Planet(0.025,1,0.4,0,0,0,0,0,2,0,1,1,22,3,3,5,23,5,0,1,0,-1,2,0,0,0,"Ganymede"));
    planets.push(new Planet(0.018,1,0.3,0,0,0,0,0,2,0,0,0,22,3,3,5,24,5,0,1,0,-1,3,5,0,0,"Callisto"));
    planets.push(new Planet(0.0001,1,0.2,0,0,0,0,0,2,0,0,0,28,1,1,6,25,5,0,1,0,-1,0,0,0,0,"Tethys"));
    planets.push(new Planet(0.0002,1,0.3,0,0,0,0,0,2,0,0,0,28,1,1,6,26,5,0,1,0,-1,1,0,0,0,"Dione"));
    planets.push(new Planet(0.0004,1,0.2,0,0,0,0,0,2,0,0,0,28,1,1,6,27,5,0,1,0,-1,2,0,0,0,"Rhea"));
    planets.push(new Planet(0.025,1,0.3,1,4,4,3,0.02,2,0,1,2,28,1,2,6,28,5,0,1,0,-1,3,1,0,0,"Titan"));
    planets.push(new Planet(0.0003,1,0.2,0,0,0,0,0,2,0,0,0,28,1,1,6,29,5,0,1,0,-1,4,4,0,0,"Iapetus"));  
    planets.push(new Planet(0.0002,1,0.3,0,0,0,0,0,2,0,0,0,33,0,0,7,30,5,0,1,0,-1,0,0,0,0,"Ariel"));
    planets.push(new Planet(0.0002,1,0.3,0,0,0,0,0,2,0,0,0,33,0,0,7,31,5,0,1,0,-1,1,5,0,0,"Umbriel"));
    planets.push(new Planet(0.0006,1,0.3,0,0,0,0,0,2,0,0,0,33,0,0,7,32,5,0,1,0,-1,2,4,0,0,"Titania"));
    planets.push(new Planet(0.0005,1,0.3,0,0,0,0,0,2,0,0,0,33,0,0,7,33,5,0,1,0,-1,3,4,0,0,"Oberon"));
    planets.push(new Planet(0.003,1,0.4,0,0,0,0,0,2,0,1,2,36,0,0,8,34,5,0,1,0,-1,0,0,0,0,"Triton"));
    planets.push(new Planet(0.00025,1,0.3,0,0,0,0,0,2,0,0,0,39,0,0,9,35,2,0,1,0,-1,0,4,0,0,"Charon"));
    planets.push(new Planet(0.00007,1,0.4,0,0,0,0,0,2,0,0,0,39,0,0,10,36,2,0,1,0,-1,0,2,0,0,"Dysnomia"));
systems.push(new System(planets,primarystartype,closecompanionpresent,closecompanionstartype,distantcompanionpresent,distantcompanionstartype,age,age,"Sol"));



div=document.createElement('div');
div.classList.add("system");
addline(`SYSTEM AGE: `+age.toFixed(1),div,"h3");
addline('',div,"h3");
addline('PRIMARY STAR(S):',div,"h3");
addline('Sol - ' + startypes[primarystartype],div,"h3","p",true);


for (var q = 0; q < 42; q++) {
    for (var l = 0; l < planets.length; l++) {
        if(planets[l].orbit == q && planets[l].starsystem==1) {
            generateplanetdesc(l,planets); 
        }
    }
}

systemcontainerinterior.appendChild(drawCanvas(planets,closecompanionpresent,distantcompanionpresent,primarystartype,closecompanionstartype,distantcompanionstartype));
systemcontainerinterior.appendChild(div);

document.getElementsByClassName("systemcontainer")[0].append(systemcontainerinterior); */
}

document.addEventListener('DOMContentLoaded', Initialize);


    </script>
  </body>
</html>