Because who needs Unity when you have turtles?
This is a simple physics engine built using Python's turtle module. It simulates basic Newtonian physics, including gravity, collision detection, and user interaction. Create and manipulate objects in a 2D space and watch them interact realistically.
- Multiple Shapes: Create circles, squares, and triangles with random sizes and colors.
- Gravity and Collision: Objects are affected by gravity and can collide with each other and the boundaries.
- Gravity Wells: Introduce gravity wells that attract nearby objects.
- User Interaction: Click to create objects, drag to move them, and use keyboard controls for various actions.
- Customizable: Adjust gravity and other parameters to change the simulation behavior.
- Click: Create a new shape at the clicked position.
- Drag: Click and drag shapes to move them.
- G Key: Create a gravity well at a random location.
- C Key: Clear all shapes and gravity wells from the screen.
- Up Arrow: Increase gravity (objects fall faster).
- Down Arrow: Decrease gravity (objects fall slower).
-
Clone the repository:
git clone https://github.com/24BS/Turtle_Physics_Engine.git
-
Navigate to the project directory:
cd Turtle_Physics_Engine -
Run the physics engine:
python3 turtle_physics_engine.py
The engine can be imported into your own projects. The main classes are
PhysicsObject and GravityWell. You can create objects, add them to the
objects list, and advance the simulation with move().
from turtle_physics_engine import PhysicsObject, GravityWell, objects
obj = PhysicsObject(0, 100, 0, 0, 'circle', 'blue')
objects.append(obj)
while True:
obj.move()The default script provides a ready-to-run example using the turtle graphics module which you can extend or embed.