/2D-gravity

2D gravity simulation in python

Primary LanguagePython

introduction

hello, this is my 2D gravity and space simulator. written in python and pyray image

usage

  • clone the code

    git clone https://github.com/9EED/2D-gravity/

  • install dependencies

    pip install pyray

  • run the code

    python3 2D-gravity.py

controlls

[tab] switch modes settings, drawing, deleting, orbits and statistics
[up][down] select a setting
[left][right] change the selected setting
[mouse left]+[drag] pan around
[mouse scroll] zoom in and out
[space] pause and unpause

settings

here you can change the basic simulation rules

  • walls: turn on and off the worlds boundries
  • walls x, walls y: change the width and height of the boundries
  • merge: turn on and off the planets merging on collision to form a new one
  • bounce: turn on and off wether planets bounce or stick on collision
  • gravity: change the effect of gravity between bodies

drawing

here you can make new planets and change their settings

  • size: how big the body is
  • density: how much mass the drawn body has, changes how much it attracts other bodies
  • static: static planets do not move, but attract others
  • random: randomizes the new planet

deleting

in this section you can delete unwanted bodies

  • delete: click to delete one by one
  • delete all: delets all bodies upon click

statistics:

general information about the simulation world

  • planets: how many are there in the world
  • velocity: sum velocity of all bodies
  • mass: sum mass of all bodies

#orbiter a tool to make planets orbit each other(still a work in progress)

  • select orbited
  • select orbiter
  • make orbit

camera

change the camera settings

  • follow: allows you to select a planet and follow it
  • release: releases the camera controlls