Skip to content

Python based physics environment builder. Mainly build to create custom environments to train reinforcement learning models.

License

Notifications You must be signed in to change notification settings

seppedelanghe/E-Builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forks Stargazers Issues MIT License


E-Builder

Python based physics environment builder. Mainly build to create custom environments to train reinforcement learning models.

View Example · Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact

About The Project

Python based physics environment builder to be used to train AI Models. You could for example recreate a game you want to train an AI model for so you can easily make actions via code and read out a score/reward.

Built With

  • Python 3.8
  • PyGame

Features

Currently the project allows you to modify the following things:

  • Environment

    • screen size
    • fixed FPS
    • Enable FPS Counter
    • Background color
  • Supported objects

    • Circle
    • Rectangle
    • Triangle
  • Non physics objects:

    • Line
  • Objects options

    • position
    • size
    • color
    • gravity
    • bounce
    • velocity (speed and direction)
    • friction (fixed rate)
    • gravitate to other object (based on mass)
  • Other

    • spring functionality
    • bounce of edges (with loss of momentum/velocity)

Examples

This is a list of the current examples that showcase what e-builder can do.

  • Bounce:
    • Bounce some balls (circles) around of the walls.
    • Apply gravity to objects
  • Edge:
    • Respawning an object on other side for continues loop of moving objects
  • Flappy:
    • Bad clone of flappy bird
    • Shows how the events and updates callbacks can be used
  • Planest:
    • A planet gravitating to the sun
    • Shows gravitateTo and velocity
  • Removal:
    • Example on how you can remove entities from the environment after the have left the screen
  • Reuse:
    • Similar to Removal, instead objects are reused and respawned at original location
  • Simple:
    • Bare bone starting template with 1 object moving up
    • This is the template for the Usage part in the README
  • Spaceship:
    • Spaceship that can apply thrust and move forward
    • Show how friction slowly slows down the object
    • Shows how arrow keys can be used to control an objects movement
  • Springs:
    • 3 circles being held under tension to create a shape
    • Example of how to use the springs funciontion

Getting Started

To use follow these steps.

Installation

  1. Clone the repo to folder ebuilder

    git clone https://github.com/seppedelanghe/E-Builder.git ebuilder
  2. (Optional) Create and activate a new conda env

    conda create -n ebuilder python=3.8
    conda activate ebuilder
  3. Install pip packages

    pip install -r requirements.txt

Usage

Creating an environment


Simple environment with 1 circle

from ebuilder.models.environment import Env
from ebuilder.models.objects import Circle

import pygame, math

WIDTH = 640
HEIGHT = 480

# Handle PyGame events here
'''
For example:
- Clicks
- Mouse events
- Quit action
- etc.

Events get triggered every frame, before updates.
'''
def events():
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            env.running = False 

# Handle entity updates here
'''
For example:
- Position
- Velocity
- Color
- etc.

Updates get triggered every frame, before drawing.
'''
def updates(entities: dict):
    pass # no action needed for this example

# Create an env that will create a window of 640px by 480px that runs at 30 FPS
env = Env(
    updates,
    events,
    size=(WIDTH, HEIGHT),
    fps=30)

# Create a ball (2D Circle) with fixed properties
ball = Circle(
        WIDTH / 2, # Middle of the screen
        HEIGHT, # Bottom of the screen
        radius=4, # Radius of 4 px
        speed=10,
        direction=-math.pi / 2, # Move up
        mass=0, # Mass of 0
        gravity=0, # no gravity
        bounce=-0, # no elasticity
        friction=0, # no friction => slowing down in air
        color=(0, 0, 0) # RBG Color black
    )

env.addEntity(ball, 'ball') # Adding the ball to the env

env.start() # Starting the env

More examples can be found in the examples folder or you can run them using the main.py file


Roadmap

Take a look at the project board Version 1 to see what features the project will have in the near future.
Or see the open issues for a list of all things in progress (bug fixes, features and more).


Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the GNU AFFERO GENERAL PUBLIC LICENSE License. See LICENSE for more information.


Contact

Seppe De Langhe - Twitter: @notSeppe

Project Link: https://github.com/seppedelanghe/E-Builder

About

Python based physics environment builder. Mainly build to create custom environments to train reinforcement learning models.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages