1.1.1 • Published 3 years ago

@meteora-digital/orbit v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Orbit System

This orbit system is an es6 class that simulates orbiting planets or bodies.

Installation

with webpack

yarn add @meteora-digital/orbit

HTML Usage

<canvas class="canvas-orbit"></canvas>
.canvas-orbit {
  width: 100vw;
  height: 100vh;
}
import OrbitSystem from '@meteora-digital/orbit';

const random = (min, max) => {
  return Math.floor(Math.random() * (max - min + 1) + min);
}

const System = new OrbitSystem(document.querySelector('canvas.canvas-orbit'));

for (var i = 0; i < 30; i++) {
  let mass = random(300,500);
  let radius = mass / 100;

  System.createBody({
    x: random(0,window.innerWidth),
    y: random(0, window.innerHeight),
    mass: mass,
    radius: radius,
  });
}

System.start();

OrbitSystem Arguments

ArgumentTypeDescription
1Dom ElementThe canvas we want to draw our system in
2ObjectOptionsDetermines global settings for our system

OrbitSystem Options

Gravity

determines the global gravity force.

{
  gravity: 1,
}

OrbitSystem Methods

createBody

Creates a new body in the system

System.createBody({
  x: random(0,window.innerWidth),
  y: random(0, window.innerHeight),
  mass: mass,
  radius: radius,
});

start

Begins the system

System.start();

stop

Stops the system

System.stop();

Body Options

OptionTypeDescriptionDefault
xNumberX Coordinate to place the body0
yNumberY Coordinate to place the body0
vNumberInitial velocity of the body0
angleNumberThe initial angle the body is moving0
massNumberHow attractive this body is1
radiusNumberThe size of our body5
boundaryNumberRadius of interactive areatrue
colorstringColour of the body'#000000'
trailnumberLength of our trails - limit this depending on computer memory0
mobileBooleanControls the mobility of the bodytrue

Inspired by

guest73's YouTube Video

License

MIT

1.1.1

3 years ago

1.1.0

3 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago