Skip to content

prasadchandan/SimplePhysics

Repository files navigation

Simple physics engine

Inspired by the following YouTube videos exploring the concept of Verlet Integration.

  1. https://www.youtube.com/watch?v=3HjO_RGIjCU
  2. https://youtu.be/PGk0rnyTa1U?t=283

This project is written in Python and uses UV for dependency management, DearPyGui for the UI, Ruff for linting, and ty for type checking.

Requirements

  • Python 3.9 or higher
  • UV - Fast Python package installer and resolver

Installation

  1. Install UV (if not already installed):

    curl -LsSf https://astral.sh/uv/install.sh | sh
  2. Clone this project:

    git clone <repository-url>
    cd SimplePhysics
  3. Install dependencies:

    uv sync

Running the Application

Run the application with one of the available examples:

# Run with the ball example (default)
uv run python app/main.py

# Run with a specific example
uv run python app/main.py --example ball
uv run python app/main.py --example box
uv run python app/main.py --example cloth
uv run python app/main.py --example double_pendulum

Development

Installing Development Dependencies

Install all dependencies including development tools:

uv sync --all-extras

Code Quality

Linting with Ruff

Check for linting issues:

uv run ruff check app/

Auto-fix linting issues:

uv run ruff check --fix app/

Format code:

uv run ruff format app/

Type Checking with ty

Run type checking:

uv run ty check app/

Testing

Run all tests:

uv run pytest

Run tests with coverage:

uv run pytest --cov=app --cov-report=html

Run specific test file:

uv run pytest tests/test_geometry.py -v

Building Binaries

Build a standalone executable for your platform:

uv run pyinstaller simplephysics.spec

The binary will be created in the dist/ directory.

For a one-off build without the spec file:

uv run pyinstaller --onefile --windowed app/main.py

CI/CD

This project uses GitHub Actions for continuous integration and deployment:

  • Linting & Type Checking: Automatically runs Ruff and ty on every push and pull request
  • Testing: Runs the full test suite with coverage reporting
  • Binary Builds: Automatically builds binaries for:
    • Windows (amd64)
    • Linux (amd64 and aarch64)
    • macOS (aarch64/Apple Silicon)

Binaries are available as artifacts from the GitHub Actions workflow runs.

Project Structure

SimplePhysics/
├── app/
│   ├── __init__.py
│   ├── main.py           # Entry point
│   ├── geometry.py       # Core geometry and physics engine
│   ├── draw.py           # Rendering with DearPyGui
│   ├── physics.py        # Physics utilities
│   └── examples/         # Example simulations
│       ├── ball.py
│       ├── box.py
│       ├── cloth.py
│       └── double_pendulum.py
├── tests/
│   ├── __init__.py
│   └── test_geometry.py  # Unit tests
├── .github/
│   └── workflows/
│       └── ci.yml        # CI/CD pipeline
├── pyproject.toml        # Project configuration
├── uv.lock              # Dependency lock file
└── README.md

Demo

Demo GIF

License

MIT

About

A very simple physics engine demo, uses verlet integration.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages