This project simulates physics interactions between sprites (squares and circles) on a terminal interface using ncurses. Sprites can be dynamically added, removed, and manipulated using commands sent via a named FIFO pipe.
The simulation supports:
- Collision detection and response.
- Gravity and restitution.
- Random sprite generation.
- Real-time command handling.
- Dynamic Sprite Addition: Add circles or squares with customizable properties.
- Collision Detection: Handles collisions between sprites with realistic velocity exchanges.
- Customizable Parameters: Adjust gravity and coefficient of restitution.
- Interactive Commands: Manage the simulation through a FIFO pipe or provided shell script.
- Random Sprite Generation: Generate multiple random sprites.
- C++ compiler (e.g.,
g++) ncurseslibrary- UNIX-like operating system (for FIFO pipes)
-
Compile the program:
g++ physcii.cpp -o physcii -lncurses -pthread
-
Run the program:
./physcii
-
Open a separate terminal to send commands:
./controller.sh
The simulation listens for commands through a FIFO pipe (/tmp/physics_fifo). The following commands are supported:
- Add a sprite:
Example:
add <shapeType (C/S)> <Name> <Size> <X_position> <Y_position> <X_velocity> <Y_velocity>add C Circle1 5 10 10 2 -3 - Remove a sprite:
Example:
remove <Name>remove Circle1 - Set gravity:
Example:
set gravity <value>set gravity 2 - Set coefficient of restitution:
Example:
set coe <value>set coe 0.8 - Generate random sprites:
Example:
random <count>random 10 - Clear all sprites:
clear - Exit the command script:
exit
The provided controller.sh simplifies interaction with the simulation. Ensure it is executable:
chmod +x controller.shRun the script:
./controller.sh- Press
qorQto quit the simulation.
- physics_simulation.cpp: Main simulation logic.
- command_script.sh: Script to send commands to the simulation via FIFO.