Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: black;
}

              
            
!

JS

              
                //super rough, afternoon coding
//I grabbed planet labs satellites after checking out their website
//https://physics.info/motion-equations/
let eph; //https://ephemerides.planet-labs.com/
let earth; //nasa image
let stars; //this is not accurately placed, but it looks pretty
let ephArray = []; //array for ephemeris file
let pos = []; //position
let vel = []; //velocity
let kappa = 6.67408e-11, //gravitational constant
  m = 1200, //mass of satellite
  M = 5.97219e24, //mass of earth
  dt = 2, //delta t
  sf = 40000; //scale factor
//simple propagation - spherical earth

function preload() {
  eph = loadTable("https://assets.codepen.io/4559259/planet+sats.csv", "csv");
  earth = loadImage("https://assets.codepen.io/4559259/earth.jpg");
  stars = loadImage("https://assets.codepen.io/4559259/starmap2.jpg");
}
function setup() {
  createCanvas(windowWidth, windowHeight, WEBGL);
  texture(earth);
  background(0);
  noStroke();
  loadData();
  smooth();
}

function draw() {
  orbitControl(0.5, 0.4, 0.01);
  background(0);
  push();
  texture(earth);
  sphere(6.378e6 / sf, 24, 50);
  pop();
  push();
  rotateY(frameCount / 10000);
  texture(stars);
  sphere(4000, 24, 50);
  pop();
  for (let i = 0; i < pos.length; i++) {
    r = sqrt(sq(pos[i].x) + sq(pos[i].y) + sq(pos[i].z));
    //g = kmM/r^2
    grav = -(kappa * m * M) / sq(r);
    //grav for x,y,z
    force = createVector(
      grav * (pos[i].x / r),
      grav * (pos[i].y / r),
      grav * (pos[i].z / r)
    );
    //acceleration  = force/mass
    accel = createVector(force.x / m, force.y / m, force.z / m);
    //velocity = v_0 + a*(dt) -> step it forward by dt
    vel[i] = createVector(
      vel[i].x + accel.x * dt,
      vel[i].y + accel.y * dt,
      vel[i].z + accel.z * dt
    );
    //position = s_0 + v*(dt)-> step it forward by dt
    pos[i] = createVector(
      pos[i].x + vel[i].x * dt,
      pos[i].y + vel[i].y * dt,
      pos[i].z + vel[i].z * dt
    );
    push();
    //translate center
    translate(pos[i].x / sf, pos[i].y / sf, pos[i].z / sf);
    //make shiny
    normalMaterial();
    sphere(0.5, 10, 10);
    //don't all sats look like this ;)
    box(2, 0.5, 0);
    pop();
  }
}
//load ephemeris into position and velocity - this could be done better
function loadData() {
  ephArray = eph.getArray();
  for (let i = 0; i < ephArray.length; i++) {
    for (let j = 0; j < 6; j++) {
      pos[i] = createVector(
        float(ephArray[i][0].replaceAll(",", "")),
        float(ephArray[i][1].replaceAll(",", "")),
        float(ephArray[i][2].replaceAll(",", ""))
      );
      vel[i] = createVector(
        float(ephArray[i][3].replaceAll(",", "")),
        float(ephArray[i][4].replaceAll(",", "")),
        float(ephArray[i][5].replaceAll(",", ""))
      );
    }
  }
}

              
            
!
999px

Console