Skip to content

24BS/Turtle_Physics_Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Turtle Physics Engine

Because who needs Unity when you have turtles?

Overview

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.

Features

  • 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.

Controls

  • 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).

Installation

  1. Clone the repository:

    git clone https://github.com/24BS/Turtle_Physics_Engine.git
  2. Navigate to the project directory:

    cd Turtle_Physics_Engine
  3. Run the physics engine:

    python3 turtle_physics_engine.py

Using as a Library

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.

About

Simple physics engine made in Pythons turtle library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages