Python based physics environment builder. Mainly build to create custom environments to train reinforcement learning models.
View Example
·
Report Bug
·
Request Feature
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.
- Python 3.8
- PyGame
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)
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
andupdates
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
To use follow these steps.
-
Clone the repo to folder ebuilder
git clone https://github.com/seppedelanghe/E-Builder.git ebuilder
-
(Optional) Create and activate a new conda env
conda create -n ebuilder python=3.8 conda activate ebuilder
-
Install pip packages
pip install -r requirements.txt
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
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).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the GNU AFFERO GENERAL PUBLIC LICENSE License. See LICENSE
for more information.
Seppe De Langhe - Twitter: @notSeppe
Project Link: https://github.com/seppedelanghe/E-Builder